Skip to content

Commit 38829bf

Browse files
authored
update phpunit version (#433)
* update phpunit version because symfony switched to namespaced phpunit code and tests fail with `PHPUnit\Framework\Constraint\Constraint' not found` * make all tests assert something * remove unnecessary line from travis config, this is configured in phpunit.xml.dist
1 parent 5b2dd3e commit 38829bf

21 files changed

+139
-130
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ env:
3030
global:
3131
- SYMFONY_DEPRECATIONS_HELPER="/.*each.*/"
3232
- SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
33-
- KERNEL_CLASS=Symfony\Cmf\Bundle\RoutingBundle\Tests\Fixtures\App\Kernel
34-
- SYMFONY_PHPUNIT_VERSION=5.7
33+
- SYMFONY_PHPUNIT_VERSION=6
3534
- TEST_INSTALLATION=false
3635

3736
matrix:

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
},
2323
"require-dev": {
2424
"doctrine/phpcr-odm": "^1.4|^2.0",
25-
"symfony/phpunit-bridge": "^3.3 || ^4.0",
26-
"matthiasnoback/symfony-dependency-injection-test": "^1.0",
27-
"matthiasnoback/symfony-config-test": "^2.2",
25+
"symfony/phpunit-bridge": "^4.2.2",
26+
"matthiasnoback/symfony-dependency-injection-test": "^2.3.1",
27+
"matthiasnoback/symfony-config-test": "^3.1.1",
2828
"doctrine/orm": "^2.5",
29-
"symfony-cmf/testing": "^2.1.0",
29+
"symfony-cmf/testing": "^2.1.11",
3030
"doctrine/data-fixtures": "^1.0.0",
3131
"symfony/validator": "^2.8 || ^3.3 || ^4.0"
3232
},
@@ -37,7 +37,8 @@
3737
},
3838
"conflict": {
3939
"doctrine/phpcr-odm": "<1.4",
40-
"phpunit/phpunit": "<5.7"
40+
"twig/twig": "<2",
41+
"phpunit/phpunit": "<6"
4142
},
4243
"autoload": {
4344
"psr-4": {

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@
2929
</exclude>
3030
</whitelist>
3131
</filter>
32+
33+
<php>
34+
<env name="KERNEL_CLASS" value="\Symfony\Cmf\Bundle\RoutingBundle\Tests\Fixtures\App\Kernel" />
35+
</php>
3236
</phpunit>

tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ public function testRedirectDoctrine()
5959
$this->assertEquals(['test' => 'toast'], $defaults);
6060
}
6161

62-
/**
63-
* @expectedException \LogicException
64-
*/
6562
public function testSetContent()
6663
{
6764
$content = $this->createMock(RouteReferrersReadInterface::class);
6865
$redirect = new RedirectRoute();
66+
$this->expectException(\LogicException::class);
6967
$redirect->setContent($content);
7068
}
7169
}

tests/Functional/Doctrine/Phpcr/RouteTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,25 @@ public function testSetPattern()
130130

131131
/**
132132
* @depends testPersistEmptyOptions
133-
*
134-
* @expectedException \InvalidArgumentException
135133
*/
136134
public function testSetPatternInvalid(Route $route)
137135
{
136+
$this->expectException(\InvalidArgumentException::class);
138137
$route->setPath('/impossible');
139138
}
140139

141-
/**
142-
* @expectedException \LogicException
143-
*/
144140
public function testInvalidIdPrefix()
145141
{
146142
$root = $this->getDm()->find(null, self::ROUTE_ROOT);
147143
$root->setPrefix('/changed'); // simulate a problem with the prefix setter listener
144+
$this->expectException(\LogicException::class);
148145
$this->assertEquals('/', $root->getPath());
149146
}
150147

151-
/**
152-
* @expectedException \LogicException
153-
*/
154148
public function testPrefixNonpersisted()
155149
{
156150
$route = new Route();
151+
$this->expectException(\LogicException::class);
157152
$route->getPath();
158153
}
159154

tests/Functional/Routing/DynamicRouterTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use Symfony\Cmf\Component\Routing\ChainRouter;
2121
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
2222
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\Routing\Exception\InvalidParameterException;
24+
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
25+
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
2326
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2427

2528
/**
@@ -122,17 +125,12 @@ public function testMatchParameters()
122125
$this->assertEquals($expected, $matches);
123126
}
124127

125-
/**
126-
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
127-
*/
128128
public function testNoMatch()
129129
{
130+
$this->expectException(ResourceNotFoundException::class);
130131
$this->router->matchRequest(Request::create('/testroute/child/123a'));
131132
}
132133

133-
/**
134-
* @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
135-
*/
136134
public function testNotAllowed()
137135
{
138136
$root = $this->getDm()->find(null, self::ROUTE_ROOT);
@@ -145,6 +143,7 @@ public function testNotAllowed()
145143
$this->getDm()->persist($route);
146144
$this->getDm()->flush();
147145

146+
$this->expectException(MethodNotAllowedException::class);
148147
$this->router->matchRequest(Request::create('/notallowed', 'POST'));
149148
}
150149

@@ -204,11 +203,9 @@ public function testMatchFormat()
204203
$this->assertEquals($expected, $matches);
205204
}
206205

207-
/**
208-
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
209-
*/
210206
public function testNoMatchingFormat()
211207
{
208+
$this->expectException(ResourceNotFoundException::class);
212209
$this->router->matchRequest(Request::create('/format/48.xml'));
213210
}
214211

@@ -361,13 +358,11 @@ public function testGenerateParameters()
361358
$this->assertEquals('/testroute/gen-slug?test=value', $url);
362359
}
363360

364-
/**
365-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
366-
*/
367361
public function testGenerateParametersInvalid()
368362
{
369363
$route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute');
370364

365+
$this->expectException(InvalidParameterException::class);
371366
$this->router->generate($route, ['slug' => 'gen-slug', 'id' => 'nonumber']);
372367
}
373368

@@ -387,13 +382,11 @@ public function testGenerateFormat()
387382
$this->assertEquals('/format/37.json', $url);
388383
}
389384

390-
/**
391-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
392-
*/
393385
public function testGenerateNoMatchingFormat()
394386
{
395387
$route = $this->getDm()->find(null, self::ROUTE_ROOT.'/format');
396388

389+
$this->expectException(InvalidParameterException::class);
397390
$this->router->generate($route, ['id' => 37, '_format' => 'xyz']);
398391
}
399392
}

tests/Unit/Controller/RedirectControllerTest.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/Unit/DependencyInjection/Compiler/ValidationPassTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function testRegisterDocumentsValidation($hasPhpcr, $hasValidator, $shoul
5454
$definition = $this->container->findDefinition('validator.builder');
5555

5656
$this->assertFalse($definition->hasMethodCall('addXmlMappings'));
57+
} else {
58+
$this->assertContainerBuilderNotHasService('validator.builder');
5759
}
5860
}
5961

tests/Unit/Doctrine/Orm/ContentRepositoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
use Doctrine\Common\Persistence\ManagerRegistry;
1515
use Doctrine\Common\Persistence\ObjectManager;
1616
use Doctrine\Common\Persistence\ObjectRepository;
17+
use PHPUnit\Framework\TestCase;
1718
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\ContentRepository;
1819

19-
class ContentRepositoryTest extends \PHPUnit_Framework_TestCase
20+
class ContentRepositoryTest extends TestCase
2021
{
2122
private $document;
2223

@@ -80,6 +81,7 @@ public function testFindCorrectModelAndId($input, $model, $id)
8081
->expects($this->any())
8182
->method('find')
8283
->with($id)
84+
->will($this->returnValue($this))
8385
;
8486

8587
$this->managerRegistry
@@ -92,6 +94,7 @@ public function testFindCorrectModelAndId($input, $model, $id)
9294
$contentRepository->setManagerName('default');
9395

9496
$foundDocument = $contentRepository->findById($input);
97+
$this->assertSame($this, $foundDocument);
9598
}
9699

97100
public function getFindCorrectModelAndIdData()

tests/Unit/Doctrine/Orm/RouteProviderTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,44 @@
1414
use Doctrine\Common\Persistence\ManagerRegistry;
1515
use Doctrine\Common\Persistence\ObjectManager;
1616
use Doctrine\ORM\EntityRepository;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
1719
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route;
1820
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\RouteProvider;
1921
use Symfony\Cmf\Component\Routing\Candidates\CandidatesInterface;
2022
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\Routing\Exception\RouteNotFoundException;
2124
use Symfony\Component\Routing\RouteCollection;
2225

23-
class RouteProviderTest extends \PHPUnit_Framework_TestCase
26+
class RouteProviderTest extends TestCase
2427
{
2528
/**
26-
* @var Route|\PHPUnit_Framework_MockObject_MockObject
29+
* @var Route|MockObject
2730
*/
2831
private $routeMock;
2932

3033
/**
31-
* @var Route|\PHPUnit_Framework_MockObject_MockObject
34+
* @var Route|MockObject
3235
*/
3336
private $route2Mock;
3437

3538
/**
36-
* @var ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject
39+
* @var ManagerRegistry|MockObject
3740
*/
3841
private $managerRegistryMock;
3942

4043
/**
41-
* @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
44+
* @var ObjectManager|MockObject
4245
*/
4346
private $objectManagerMock;
4447

4548
/**
46-
* @var EntityRepository|\PHPUnit_Framework_MockObject_MockObject
49+
* @var EntityRepository|MockObject
4750
*/
4851
private $objectRepositoryMock;
4952

5053
/**
51-
* @var CandidatesInterface|\PHPUnit_Framework_MockObject_MockObject
54+
* @var CandidatesInterface|MockObject
5255
*/
5356
private $candidatesMock;
5457

@@ -161,9 +164,6 @@ public function testGetRouteByName()
161164
$this->assertSame($this->routeMock, $foundRoute);
162165
}
163166

164-
/**
165-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
166-
*/
167167
public function testGetRouteByNameNotFound()
168168
{
169169
$this->objectRepositoryMock
@@ -176,12 +176,10 @@ public function testGetRouteByNameNotFound()
176176
$routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock, 'Route');
177177
$routeProvider->setManagerName('default');
178178

179+
$this->expectException(RouteNotFoundException::class);
179180
$routeProvider->getRouteByName('/test-route');
180181
}
181182

182-
/**
183-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
184-
*/
185183
public function testGetRouteByNameNotCandidate()
186184
{
187185
$this->objectRepositoryMock
@@ -199,6 +197,7 @@ public function testGetRouteByNameNotCandidate()
199197
$routeProvider = new RouteProvider($this->managerRegistryMock, $candidatesMock, 'Route');
200198
$routeProvider->setManagerName('default');
201199

200+
$this->expectException(RouteNotFoundException::class);
202201
$routeProvider->getRouteByName('/test-route');
203202
}
204203

0 commit comments

Comments
 (0)