Skip to content

Commit

Permalink
Merge pull request #541 from alexislefebvre/allow-phpunit-8
Browse files Browse the repository at this point in the history
Allow PHPUnit 8
  • Loading branch information
alexislefebvre authored Nov 3, 2019
2 parents 22317d2 + 66d0789 commit d3f7238
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 71 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"require": {
"php": "^7.1",
"doctrine/annotations": "^1.3",
"phpunit/phpunit": "^7.5.0 || ^8.0",
"symfony/browser-kit": "^3.4 || ^4.1",
"symfony/framework-bundle": "^3.4 || ^4.1"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.8",
"doctrine/orm": "^2.6",
"phpunit/phpunit": "^6.1 || ^7.0",
"symfony/monolog-bundle": "^3.1",
"symfony/monolog-bundle": "^3.2",
"symfony/phpunit-bridge": "^3.4 || ^4.1",
"symfony/symfony": "^3.4 || ^4.1",
"twig/twig": "^2.0"
Expand Down
2 changes: 1 addition & 1 deletion doc/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Get the content of an URL:
$content = $this->fetchContent('/contact');

// `filter()` can't be used since the output is HTML code, check the content directly
$this->assertContains(
$this->assertStringContainsString(
'<h1>LiipFunctionalTestBundle</h1>',
$content
);
Expand Down
4 changes: 2 additions & 2 deletions doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ExampleFunctionalTest extends WebTestCase
$this->assertSame('Hello foo!', $content);

// check if the logout button is shown
$this->assertContains('logout', $content);
$this->assertStringContainsString('logout', $content);
}

public function test404Page(): void
Expand All @@ -88,7 +88,7 @@ class ExampleFunctionalTest extends WebTestCase
public function testLoginPage(): void
{
$content = $this->fetchContent('/', 'GET', false);
$this->assertContains('login', $content);
$this->assertStringContainsString('login', $content);
}

public function testValidationErrors(): void
Expand Down
1 change: 0 additions & 1 deletion src/Test/ValidationErrorsConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function __construct(array $expect)
{
$this->expect = $expect;
sort($this->expect);
parent::__construct();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/CommandConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function testRunCommand(): void
$this->assertInstanceOf(CommandTester::class, $this->commandTester);

// Test values from configuration
$this->assertContains('Environment: test', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringContainsString('Environment: test', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());

$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertFalse($this->getDecorated());
}
}
85 changes: 42 additions & 43 deletions tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function testRunCommandWithoutOptionsAndReuseKernel(): void
$this->commandTester = $this->runCommand('liipfunctionaltestbundle:test');

// Test default values
$this->assertContains('Environment: test', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Environment: test', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertFalse($this->commandTester->getInput()->isInteractive());

$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertTrue($this->getDecorated());

// Run command and reuse kernel
Expand All @@ -44,8 +44,8 @@ public function testRunCommandWithoutOptionsAndReuseKernel(): void
$this->assertInstanceOf(CommandTester::class, $this->commandTester);
$this->assertEquals(0, $this->commandTester->getStatusCode());

$this->assertContains('Environment: test', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Environment: test', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
}

public function testRunCommandWithInputs(): void
Expand Down Expand Up @@ -79,10 +79,10 @@ public function testRunCommandWithoutOptionsAndNotReuseKernel(): void
$this->assertEquals(0, $this->commandTester->getStatusCode());

// Test default values
$this->assertContains('Environment: test', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Environment: test', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());

$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertTrue($this->getDecorated());

// Run command and not reuse kernel
Expand All @@ -91,8 +91,8 @@ public function testRunCommandWithoutOptionsAndNotReuseKernel(): void

$this->assertInstanceOf(CommandTester::class, $this->commandTester);

$this->assertContains('Environment: prod', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Environment: prod', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
}

public function testRunCommandWithoutDecoration(): void
Expand All @@ -105,9 +105,9 @@ public function testRunCommandWithoutDecoration(): void
$this->assertInstanceOf(CommandTester::class, $this->commandTester);
$this->assertEquals(0, $this->commandTester->getStatusCode());

$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());

$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertFalse($this->getDecorated());
}

Expand All @@ -117,7 +117,7 @@ public function testRunCommandVerbosityQuiet(): void
$this->assertSame(OutputInterface::VERBOSITY_QUIET, $this->getVerbosityLevel());

$this->isDecorated(false);
$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertFalse($this->getDecorated());

$this->commandTester = $this->runCommand('liipfunctionaltestbundle:test');
Expand All @@ -126,10 +126,10 @@ public function testRunCommandVerbosityQuiet(): void
$this->assertEquals(0, $this->commandTester->getStatusCode());

$this->assertEmpty($this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: DEBUG', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: DEBUG', $this->commandTester->getDisplay());
}

public function testRunCommandVerbosityImplicitlyNormal(): void
Expand All @@ -138,18 +138,18 @@ public function testRunCommandVerbosityImplicitlyNormal(): void
$this->assertSame(OutputInterface::VERBOSITY_NORMAL, $this->getVerbosityLevel());

$this->isDecorated(false);
$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertFalse($this->getDecorated());

$this->commandTester = $this->runCommand('liipfunctionaltestbundle:test');
$this->assertEquals(0, $this->commandTester->getStatusCode());

$this->assertInstanceOf(CommandTester::class, $this->commandTester);

$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: DEBUG', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: DEBUG', $this->commandTester->getDisplay());
}

public function testRunCommandVerbosityExplicitlyNormal(): void
Expand All @@ -163,10 +163,10 @@ public function testRunCommandVerbosityExplicitlyNormal(): void

$this->assertInstanceOf(CommandTester::class, $this->commandTester);

$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: DEBUG', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: DEBUG', $this->commandTester->getDisplay());
}

public function testRunCommandVerbosityVerbose(): void
Expand All @@ -179,10 +179,10 @@ public function testRunCommandVerbosityVerbose(): void

$this->assertInstanceOf(CommandTester::class, $this->commandTester);

$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: DEBUG', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: DEBUG', $this->commandTester->getDisplay());
}

public function testRunCommandVerbosityVeryVerbose(): void
Expand All @@ -191,18 +191,18 @@ public function testRunCommandVerbosityVeryVerbose(): void
$this->assertSame(OutputInterface::VERBOSITY_VERY_VERBOSE, $this->getVerbosityLevel());

$this->isDecorated(false);
$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertFalse($this->getDecorated());

$this->commandTester = $this->runCommand('liipfunctionaltestbundle:test');
$this->assertEquals(0, $this->commandTester->getStatusCode());

$this->assertInstanceOf(CommandTester::class, $this->commandTester);

$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertNotContains('Verbosity level: DEBUG', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringNotContainsString('Verbosity level: DEBUG', $this->commandTester->getDisplay());
}

public function testRunCommandVerbosityDebug(): void
Expand All @@ -211,18 +211,18 @@ public function testRunCommandVerbosityDebug(): void
$this->assertSame(OutputInterface::VERBOSITY_DEBUG, $this->getVerbosityLevel());

$this->isDecorated(false);
$this->assertInternalType('boolean', $this->getDecorated());
$this->assertIsBool($this->getDecorated());
$this->assertFalse($this->getDecorated());

$this->commandTester = $this->runCommand('liipfunctionaltestbundle:test');
$this->assertEquals(0, $this->commandTester->getStatusCode());

$this->assertInstanceOf(CommandTester::class, $this->commandTester);

$this->assertContains('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertContains('Verbosity level: DEBUG', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: NORMAL', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: VERBOSE', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: VERY_VERBOSE', $this->commandTester->getDisplay());
$this->assertStringContainsString('Verbosity level: DEBUG', $this->commandTester->getDisplay());
}

public function testRunCommandStatusCode(): void
Expand All @@ -234,13 +234,12 @@ public function testRunCommandStatusCode(): void
$this->assertEquals(10, $this->commandTester->getStatusCode());
}

/**
* @expectedException \OutOfBoundsException
*/
public function testRunCommandVerbosityOutOfBound(): void
{
$this->setVerbosityLevel('foobar');

$this->expectException(\OutOfBoundsException::class);

$this->runCommand('liipfunctionaltestbundle:test');
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Command/ParatestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public function testParatest(): void
'options' => 'Tests/Test/WebTestCaseTest.php',
]);

$this->assertContains('Running phpunit in 3 processes with vendor/bin/phpunit', $content);
$this->assertContains('Initial schema created', $content);
$this->assertNotContains('Error : Install paratest first', $content);
$this->assertContains('Done...Running test.', $content);
$this->assertStringContainsString('Running phpunit in 3 processes with vendor/bin/phpunit', $content);
$this->assertStringContainsString('Initial schema created', $content);
$this->assertStringNotContainsString('Error : Install paratest first', $content);
$this->assertStringContainsString('Done...Running test.', $content);

$this->assertContains(
$this->assertStringContainsString(
'OK (22 tests, 69 assertions)',
$content
);
Expand Down
8 changes: 4 additions & 4 deletions tests/Test/WebTestCaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ public function testIndexAuthenticationLoginAs(): void
*
* There will be 2 queries, in the configuration the limit is 1,
* an Exception will be thrown.
*
* @expectedException \Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException
*/
public function testAllowedQueriesExceededException(): void
{
Expand All @@ -160,6 +158,8 @@ public function testAllowedQueriesExceededException(): void
// One another query to load the second user.
$path = '/user/2';

$this->expectException(\Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException::class);

$this->client->request('GET', $path);
}

Expand All @@ -170,8 +170,6 @@ public function testAllowedQueriesExceededException(): void
*
* There will be 1 query, in the annotation the limit is 0,
* an Exception will be thrown.
*
* @expectedException \Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException
*/
public function testAnnotationAndException(): void
{
Expand All @@ -180,6 +178,8 @@ public function testAnnotationAndException(): void
// One query to load the second user
$path = '/user/1';

$this->expectException(\Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException::class);

$this->client->request('GET', $path);
}
}
20 changes: 10 additions & 10 deletions tests/Test/WebTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testGetUrl(): void
]
);

$this->assertInternalType('string', $path);
$this->assertIsString($path);

$this->assertSame($path, '/user/1?get_parameter=abc');
}
Expand Down Expand Up @@ -152,9 +152,9 @@ public function testAssertStatusCodeException(): void
try {
$this->assertStatusCode(-1, $this->client);
} catch (AssertionFailedError $e) {
$this->assertContains('No route found for "GET /9999"', $e->getMessage());
$this->assertContains('Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(', $e->getMessage());
$this->assertContains('Failed asserting that 404 matches expected -1.', $e->getMessage());
$this->assertStringContainsString('No route found for "GET /9999"', $e->getMessage());
$this->assertStringContainsString('Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(', $e->getMessage());
$this->assertStringContainsString('Failed asserting that 404 matches expected -1.', $e->getMessage());

return;
}
Expand Down Expand Up @@ -211,9 +211,9 @@ public function testIndexFetchContent(): void

$content = $this->fetchContent($path);

$this->assertInternalType('string', $content);
$this->assertIsString($content);

$this->assertContains(
$this->assertStringContainsString(
'<h1>LiipFunctionalTestBundle</h1>',
$content
);
Expand Down Expand Up @@ -285,7 +285,7 @@ public function testForm(): void

$this->assertStatusCode(200, $this->client);

$this->assertContains(
$this->assertStringContainsString(
'Name submitted.',
$crawler->filter('div.flash-notice')->text()
);
Expand Down Expand Up @@ -318,16 +318,14 @@ public function testFormWithEmbed(): void

$this->assertStatusCode(200, $this->client);

$this->assertContains(
$this->assertStringContainsString(
'Name submitted.',
$crawler->filter('div.flash-notice')->text()
);
}

/**
* @depends testForm
*
* @expectedException \PHPUnit\Framework\ExpectationFailedException
*/
public function testFormWithException(): void
{
Expand All @@ -342,6 +340,8 @@ public function testFormWithException(): void

$this->assertStatusCode(200, $this->client);

$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class);

$this->assertValidationErrors([''], $this->client->getContainer());
}

Expand Down

0 comments on commit d3f7238

Please sign in to comment.