Skip to content

Commit 2528c68

Browse files
committed
Updated composer libraries.
Fixed tests
1 parent 4e13d5f commit 2528c68

File tree

11 files changed

+91
-50
lines changed

11 files changed

+91
-50
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
}
99
],
1010
"require": {
11-
"php": ">=5.5.0",
11+
"php": ">=7.0",
1212
"illuminate/support": "~5.0",
13-
"mockery/mockery": "~0.9"
13+
"mockery/mockery": "~1.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "~4.0"
16+
"phpunit/phpunit": "~6.0"
1717
},
1818
"autoload": {
1919
"psr-0": {

src/Briedis/ApiBuilder/Method.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Briedis\ApiBuilder\Exceptions\InvalidStructureException;
88
use Illuminate\Contracts\Validation\ValidatesWhenResolved;
9-
use Illuminate\Support\Str;
109

1110
abstract class Method implements ValidatesWhenResolved
1211
{
@@ -68,4 +67,15 @@ public function validate()
6867
$validator = new StructureValidator($requestStructure);
6968
$validator->validate(\Request::input());
7069
}
70+
71+
/**
72+
* Retrieve input field (or all)
73+
* @param string|null $key
74+
* @param mixed|null $default
75+
* @return mixed
76+
*/
77+
public function input($key = null, $default = null)
78+
{
79+
return \Request::input($key, $default);
80+
}
7181
}

tests/.gitkeep

Whitespace-only changes.

tests/Stubs/GetMethodStub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ public function getRequest()
1717
public function getResponse()
1818
{
1919
}
20+
21+
public function validateResolved()
22+
{
23+
}
2024
}

tests/Stubs/InvalidMethodStub.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InvalidMethodStub extends Method
88
{
99
const METHOD = 'UNKNOWN-METHOD';
1010

11-
const URI = 'doesnt-matter';
11+
const URI = 'does-not-matter';
1212

1313
public function getRequest()
1414
{
@@ -17,4 +17,8 @@ public function getRequest()
1717
public function getResponse()
1818
{
1919
}
20+
21+
public function validateResolved()
22+
{
23+
}
2024
}

tests/Stubs/PostMethodStub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ public function getRequest()
1717
public function getResponse()
1818
{
1919
}
20+
21+
public function validateResolved()
22+
{
23+
}
2024
}

tests/TestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Briedis\ApiBuilder\Tests;
4+
5+
use Mockery;
6+
7+
abstract class TestCase extends \PHPUnit\Framework\TestCase
8+
{
9+
protected function tearDown()
10+
{
11+
Mockery::close();
12+
parent::tearDown();
13+
}
14+
}
Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
<?php
1+
<?php /** @noinspection PhpUnhandledExceptionInspection */
22

3-
namespace Briedis\ApiBuilder\Tests;
3+
namespace Briedis\ApiBuilder\Tests\Unit;
44

55
use Briedis\ApiBuilder\Exceptions\InvalidStructureException;
66
use Briedis\ApiBuilder\Items\DecimalItem;
77
use Briedis\ApiBuilder\StructureBuilder;
8-
use Briedis\ApiBuilder\StructureBuilder as SB;
98
use Briedis\ApiBuilder\StructureValidator;
10-
use PHPUnit_Framework_TestCase;
9+
use Briedis\ApiBuilder\Tests\TestCase;
1110

12-
class MultiDepthValidatorTest extends PHPUnit_Framework_TestCase
11+
class MultiDepthValidatorTest extends TestCase
1312
{
14-
/** @var SB */
13+
/** @var StructureBuilder */
1514
private $s;
1615

1716
/** @var StructureValidator */
1817
private $v;
1918

2019
protected function setUp()
2120
{
22-
$this->s = new SB;
21+
parent::setUp();
22+
23+
$this->s = new StructureBuilder;
2324
$this->v = new StructureValidator($this->s);
2425
}
2526

2627
public function testValidStructure()
2728
{
2829
$this->s
29-
->struct('s1', (new SB)
30+
->struct('s1', (new StructureBuilder)
3031
->int('id')
31-
)->struct('s2', (new SB)
32+
)->struct('s2', (new StructureBuilder)
3233
->float('decimal')
3334
)->str('str');
3435

@@ -50,10 +51,10 @@ public function testInvalidStructure()
5051
$caught = false;
5152

5253
$this->s
53-
->struct('s11', (new SB)
54+
->struct('s11', (new StructureBuilder)
5455
->float('decimal')
5556
)
56-
->struct('s22', (new SB)
57+
->struct('s22', (new StructureBuilder)
5758
->float('decimal')
5859
);
5960

@@ -81,11 +82,11 @@ public function testInvalidStructure()
8182
public function testVeryDeepValidStructure()
8283
{
8384
$this->s
84-
->struct('s111', (new SB)
85-
->struct('s222', (new SB)
86-
->struct('s333', (new SB)
87-
->struct('s444', (new SB)
88-
->struct('s555', (new SB)
85+
->struct('s111', (new StructureBuilder)
86+
->struct('s222', (new StructureBuilder)
87+
->struct('s333', (new StructureBuilder)
88+
->struct('s444', (new StructureBuilder)
89+
->struct('s555', (new StructureBuilder)
8990
->int('id')
9091
)
9192
)
@@ -115,12 +116,12 @@ public function testWrongParameterDepth()
115116
{
116117
$this->s
117118
->str('1_1')
118-
->struct('1_3', (new SB)
119+
->struct('1_3', (new StructureBuilder)
119120
->str('2_1')
120-
->struct('2_2', (new SB)
121+
->struct('2_2', (new StructureBuilder)
121122
->str('3_1')
122-
->struct('3_2', (new SB)
123-
->struct('4_1', (new SB)
123+
->struct('3_2', (new StructureBuilder)
124+
->struct('4_1', (new StructureBuilder)
124125
->bool('5_1')
125126
->int('5_2')
126127
)
@@ -167,12 +168,13 @@ public function testValidArrayOfStructures()
167168
->str('name')
168169
->str('status')->values(['one', 'two', 'three'])->optional();
169170

170-
$whole = (new SB)
171+
$whole = (new StructureBuilder)
171172
->int('someId')
172173
->struct('items', $item)->multiple();
173174

174175
$structureValidator = new StructureValidator($whole);
175-
$structureValidator->validate([
176+
177+
$result = $structureValidator->validate([
176178
'someId' => 666,
177179
'items' => [
178180
[
@@ -191,6 +193,8 @@ public function testValidArrayOfStructures()
191193
],
192194
],
193195
]);
196+
197+
self::assertTrue($result);
194198
}
195199

196200
public function testInvalidArrayOfStructures()
@@ -199,7 +203,7 @@ public function testInvalidArrayOfStructures()
199203
->int('id')
200204
->str('name');
201205

202-
$whole = (new SB)->struct('items', $item)->multiple();
206+
$whole = (new StructureBuilder)->struct('items', $item)->multiple();
203207

204208
$structureValidator = new StructureValidator($whole);
205209

@@ -228,7 +232,7 @@ public function testStructureOfArrayReceivesInvalidStructure()
228232
->int('id')
229233
->str('name');
230234

231-
$whole = (new SB)->struct('items', $item)->multiple();
235+
$whole = (new StructureBuilder)->struct('items', $item)->multiple();
232236

233237
$structureValidator = new StructureValidator($whole);
234238

@@ -250,7 +254,7 @@ public function testOptionalStructuresCanBeNull()
250254
{
251255
$item = (new StructureBuilder('MyStructure'));
252256

253-
$whole = (new SB)->struct('item', $item)->optional();
257+
$whole = (new StructureBuilder)->struct('item', $item)->optional();
254258

255259
$structureValidator = new StructureValidator($whole);
256260

Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
<?php
22

3-
namespace Briedis\ApiBuilder\Tests;
3+
namespace Briedis\ApiBuilder\Tests\Unit;
44

55
use Briedis\ApiBuilder\RouteBuilder;
66
use Briedis\ApiBuilder\Tests\Stubs\GetMethodStub;
77
use Briedis\ApiBuilder\Tests\Stubs\InvalidMethodStub;
88
use Briedis\ApiBuilder\Tests\Stubs\PostMethodStub;
9+
use Briedis\ApiBuilder\Tests\TestCase;
910
use Illuminate\Contracts\Routing\Registrar;
1011
use Mockery;
1112
use Mockery\Mock;
1213
use Mockery\MockInterface;
13-
use PHPUnit_Framework_TestCase;
1414

15-
class RouteBuilderTest extends PHPUnit_Framework_TestCase
15+
class RouteBuilderTest extends TestCase
1616
{
1717
/** @var Registrar|MockInterface|Mock */
1818
private $mock;
1919

2020
/** @var RouteBuilder */
2121
private $builder;
2222

23-
24-
public static function tearDownAfterClass()
25-
{
26-
Mockery::close();
27-
parent::tearDownAfterClass();
28-
}
29-
3023
protected function setUp()
3124
{
3225
parent::setUp();
26+
3327
$this->mock = Mockery::mock(Registrar::class);
3428
$this->builder = new RouteBuilder($this->mock);
3529
}
@@ -38,20 +32,24 @@ public function testGetMethod()
3832
{
3933
$method = new GetMethodStub;
4034
$this->mock->shouldReceive('get')->once();
41-
$this->builder->add($method, 'action');
35+
$result = $this->builder->add($method, 'action');
36+
37+
self::assertInstanceOf(RouteBuilder::class, $result);
4238
}
4339

4440
public function testPostMethod()
4541
{
4642
$method = new PostMethodStub;
4743
$this->mock->shouldReceive('post')->once();
48-
$this->builder->add($method, 'controller@method');
44+
$result = $this->builder->add($method, 'controller@method');
45+
46+
self::assertInstanceOf(RouteBuilder::class, $result);
4947
}
5048

5149
public function testInvalidMethod()
5250
{
5351
$method = new InvalidMethodStub;
54-
self::setExpectedException(\InvalidArgumentException::class);
52+
self::expectException(\InvalidArgumentException::class);
5553
$this->builder->add($method, 'controller@method');
5654
}
5755
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?php
2+
/** @noinspection PhpUnhandledExceptionInspection */
23

3-
namespace Briedis\ApiBuilder\Tests;
4+
namespace Briedis\ApiBuilder\Tests\Unit;
45

56
use Briedis\ApiBuilder\Exceptions\InvalidStructureException;
67
use Briedis\ApiBuilder\Items\DecimalItem;
78
use Briedis\ApiBuilder\Items\IntegerItem;
89
use Briedis\ApiBuilder\StructureBuilder;
910
use Briedis\ApiBuilder\StructureValidator;
10-
use PHPUnit_Framework_TestCase;
11+
use Briedis\ApiBuilder\Tests\TestCase;
1112

12-
class SingleDepthValidatorTest extends PHPUnit_Framework_TestCase
13+
class SingleDepthValidatorTest extends TestCase
1314
{
1415
/** @var StructureBuilder */
1516
private $s;
@@ -19,6 +20,8 @@ class SingleDepthValidatorTest extends PHPUnit_Framework_TestCase
1920

2021
protected function setUp()
2122
{
23+
parent::setUp();
24+
2225
$this->s = new StructureBuilder;
2326
$this->v = new StructureValidator($this->s);
2427
}
@@ -145,6 +148,6 @@ public function testOptionalWillAcceptNullValue()
145148
$input = [
146149
'canBeNull' => null,
147150
];
148-
$this->assertTrue($this->v->validate($input), 'Optional parameter can be nullable');
151+
$this->assertTrue($this->v->validate($input), 'Optional parameter can be null');
149152
}
150153
}

0 commit comments

Comments
 (0)