Skip to content

Commit

Permalink
Merge pull request #313 from carusogabriel/assertions
Browse files Browse the repository at this point in the history
Use dedicated PHPUnit assertions
  • Loading branch information
andreasschroth authored Apr 12, 2018
2 parents d47a5c9 + 1f35ef3 commit 57eab83
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion test/functional/PHPUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function testRunWithFatalParseErrorsHasExitCode255or1()
$proc = $this->invokeParatest('fatal-tests/UnitTestWithFatalParseErrorTest.php', [
'bootstrap' => BOOTSTRAP,
]);
$this->assertTrue(in_array($proc->getExitCode(), [1, 255], true));
$this->assertContains($proc->getExitCode(), [1, 255]);
}

public function testStopOnFailurePreventsStartingFurtherTestsAfterFailure()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ParaTest/Runners/PHPUnit/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ private function assertJUnitLogIsValid($logFile)
$this->assertFileExists($logFile, "Failed asserting that $logFile exists.");
$log = new SimpleXMLElement(file_get_contents($logFile));
$count = count($log->testsuite->testcase);
$this->assertTrue($count > 1, 'Not even a test has been executed');
$this->assertGreaterThan(1, $count, 'Not even a test has been executed');
}
}
2 changes: 1 addition & 1 deletion test/functional/SkippedOrIncompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testDataProviderWithSkippedInDefaultMode()
protected function assertContainsNSkippedTests($n, $output)
{
preg_match('/\n\n([\.ISEF].*)\n\nTime/s', $output, $matches);
$this->assertEquals(2, count($matches));
$this->assertCount(2, $matches);
$numberOfS = substr_count($matches[1], 'S');
$this->assertEquals($n, $numberOfS, "The test should have skipped $n tests, instead it skipped $numberOfS, $matches[1]");
}
Expand Down
26 changes: 13 additions & 13 deletions test/unit/Logging/JUnit/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testIsSingleSuiteReturnsFalseForMultipleSuites()
public function testMixedSuiteShouldConstructRootSuite()
{
$suites = $this->mixed->getSuites();
$this->assertEquals(1, count($suites));
$this->assertCount(1, $suites);
$this->assertEquals('test/fixtures/tests/', $suites[0]->name);
$this->assertEquals('7', $suites[0]->tests);
$this->assertEquals('6', $suites[0]->assertions);
Expand All @@ -62,7 +62,7 @@ public function testMixedSuiteShouldConstructRootSuite()
*/
public function testMixedSuiteConstructsChildSuites($suite)
{
$this->assertEquals(3, count($suite->suites));
$this->assertCount(3, $suite->suites);
$first = $suite->suites[0];
$this->assertEquals('UnitTestWithClassAnnotationTest', $first->name);
$this->assertEquals('/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithClassAnnotationTest.php', $first->file);
Expand All @@ -82,7 +82,7 @@ public function testMixedSuiteConstructsChildSuites($suite)
*/
public function testMixedSuiteConstructsTestCases($suite)
{
$this->assertEquals(3, count($suite->cases));
$this->assertCount(3, $suite->cases);
$first = $suite->cases[0];
$this->assertEquals('testTruth', $first->name);
$this->assertEquals('UnitTestWithClassAnnotationTest', $first->class);
Expand All @@ -96,7 +96,7 @@ public function testMixedSuiteCasesLoadFailures()
{
$suites = $this->mixed->getSuites();
$case = $suites[0]->suites[0]->cases[1];
$this->assertEquals(1, count($case->failures));
$this->assertCount(1, $case->failures);
$failure = $case->failures[0];
$this->assertEquals(ExpectationFailedException::class, $failure['type']);
$this->assertEquals("UnitTestWithClassAnnotationTest::testFalsehood\nFailed asserting that true is false.\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithClassAnnotationTest.php:20", $failure['text']);
Expand All @@ -106,7 +106,7 @@ public function testMixedSuiteCasesLoadErrors()
{
$suites = $this->mixed->getSuites();
$case = $suites[0]->suites[1]->cases[0];
$this->assertEquals(1, count($case->errors));
$this->assertCount(1, $case->errors);
$error = $case->errors[0];
$this->assertEquals('Exception', $error['type']);
$this->assertEquals("UnitTestWithErrorTest::testTruth\nException: Error!!!\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithErrorTest.php:12", $error['text']);
Expand All @@ -115,7 +115,7 @@ public function testMixedSuiteCasesLoadErrors()
public function testSingleSuiteShouldConstructRootSuite()
{
$suites = $this->single->getSuites();
$this->assertEquals(1, count($suites));
$this->assertCount(1, $suites);
$this->assertEquals('UnitTestWithMethodAnnotationsTest', $suites[0]->name);
$this->assertEquals('/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithMethodAnnotationsTest.php', $suites[0]->file);
$this->assertEquals('3', $suites[0]->tests);
Expand All @@ -134,7 +134,7 @@ public function testSingleSuiteShouldConstructRootSuite()
*/
public function testSingleSuiteShouldHaveNoChildSuites($suite)
{
$this->assertEquals(0, count($suite->suites));
$this->assertCount(0, $suite->suites);
}

/**
Expand All @@ -144,7 +144,7 @@ public function testSingleSuiteShouldHaveNoChildSuites($suite)
*/
public function testSingleSuiteConstructsTestCases($suite)
{
$this->assertEquals(3, count($suite->cases));
$this->assertCount(3, $suite->cases);
$first = $suite->cases[0];
$this->assertEquals('testTruth', $first->name);
$this->assertEquals('UnitTestWithMethodAnnotationsTest', $first->class);
Expand All @@ -158,7 +158,7 @@ public function testSingleSuiteCasesLoadFailures()
{
$suites = $this->single->getSuites();
$case = $suites[0]->cases[1];
$this->assertEquals(1, count($case->failures));
$this->assertCount(1, $case->failures);
$failure = $case->failures[0];
$this->assertEquals(ExpectationFailedException::class, $failure['type']);
$this->assertEquals("UnitTestWithMethodAnnotationsTest::testFalsehood\nFailed asserting that true is false.\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithMethodAnnotationsTest.php:18", $failure['text']);
Expand All @@ -167,7 +167,7 @@ public function testSingleSuiteCasesLoadFailures()
public function testEmptySuiteConstructsTestCase()
{
$suites = $this->empty->getSuites();
$this->assertEquals(1, count($suites));
$this->assertCount(1, $suites);

$suite = $suites[0];
$this->assertEquals('', $suite->name);
Expand Down Expand Up @@ -200,22 +200,22 @@ public function testSingleGetTotals()
public function testMixedGetFailureMessages()
{
$failures = $this->mixed->getFailures();
$this->assertEquals(2, count($failures));
$this->assertCount(2, $failures);
$this->assertEquals("UnitTestWithClassAnnotationTest::testFalsehood\nFailed asserting that true is false.\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithClassAnnotationTest.php:20", $failures[0]);
$this->assertEquals("UnitTestWithMethodAnnotationsTest::testFalsehood\nFailed asserting that true is false.\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithMethodAnnotationsTest.php:18", $failures[1]);
}

public function testMixedGetErrorMessages()
{
$errors = $this->mixed->getErrors();
$this->assertEquals(1, count($errors));
$this->assertCount(1, $errors);
$this->assertEquals("UnitTestWithErrorTest::testTruth\nException: Error!!!\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithErrorTest.php:12", $errors[0]);
}

public function testSingleGetMessages()
{
$failures = $this->single->getFailures();
$this->assertEquals(1, count($failures));
$this->assertCount(1, $failures);
$this->assertEquals("UnitTestWithMethodAnnotationsTest::testFalsehood\nFailed asserting that true is false.\n\n/home/brian/Projects/parallel-phpunit/test/fixtures/tests/UnitTestWithMethodAnnotationsTest.php:18", $failures[0]);
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/Logging/JUnit/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ public function testThatEmptyLineAttributesConvertToZero()
$writer = new Writer($this->interpreter, 'test/fixtures/tests/');
$xml = $writer->getXml();

$this->assertFalse(strpos($xml, 'line=""'), 'Expected no empty line attributes (line=""), but found one.');
$this->assertNotContains('line=""', $xml, 'Expected no empty line attributes (line=""), but found one.');
}
}
10 changes: 5 additions & 5 deletions test/unit/Logging/LogInterpreterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testAddReaderIncrementsReaders()
{
$reader = $this->getMockReader();
$this->interpreter->addReader($reader);
$this->assertEquals(3, count($this->getObjectValue($this->interpreter, 'readers')));
$this->assertCount(3, $this->getObjectValue($this->interpreter, 'readers'));
}

public function testAddReaderReturnsSelf()
Expand All @@ -45,7 +45,7 @@ public function testGetReaders()
$reader = $this->getMockReader();
$this->interpreter->addReader($reader);
$readers = $this->interpreter->getReaders();
$this->assertEquals(3, count($readers));
$this->assertCount(3, $readers);
$last = array_pop($readers);
$this->assertSame($reader, $last);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function testGetFailuresReturnsArrayOfFailureMessages()
public function testGetCasesReturnsAllCases()
{
$cases = $this->interpreter->getCases();
$this->assertEquals(10, count($cases));
$this->assertCount(10, $cases);
}

public function testGetCasesExtendEmptyCasesFromSuites()
Expand All @@ -124,7 +124,7 @@ public function testGetCasesExtendEmptyCasesFromSuites()
$dataProviderReader = $this->getReader('dataProviderSuite');
$interpreter->addReader($dataProviderReader);
$cases = $interpreter->getCases();
$this->assertEquals(10, count($cases));
$this->assertCount(10, $cases);
foreach ($cases as $name => $case) {
$this->assertAttributeNotEmpty('class', $case);
$this->assertAttributeNotEmpty('file', $case);
Expand All @@ -148,7 +148,7 @@ public function testGetCasesExtendEmptyCasesFromSuites()
public function testFlattenCasesReturnsCorrectNumberOfSuites()
{
$suites = $this->interpreter->flattenCases();
$this->assertEquals(4, count($suites));
$this->assertCount(4, $suites);

return $suites;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Parser/ParsedClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGetMethodsMultipleAnnotationsReturnsMethods()
public function testGetMethodsExceptsAdditionalAnnotationFilter()
{
$group1 = $this->class->getMethods(['group' => 'group1']);
$this->assertEquals(1, count($group1));
$this->assertCount(1, $group1);
$this->assertEquals($this->methods[0], $group1[0]);
}
}
4 changes: 2 additions & 2 deletions test/unit/Parser/ParserTest/GetClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public function testParsedClassHasNamespace()
public function testParsedClassHasCorrectNumberOfTestMethods()
{
$class = $this->parseFile($this->fixture('failing-tests/UnitTestWithClassAnnotationTest.php'));
$this->assertEquals(4, count($class->getMethods()));
$this->assertCount(4, $class->getMethods());
}

public function testParsedClassWithParentHasCorrectNumberOfTestMethods()
{
$class = $this->parseFile($this->fixture('failing-tests/UnitTestWithErrorTest.php'));
$this->assertEquals(4, count($class->getMethods()));
$this->assertCount(4, $class->getMethods());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Runners/PHPUnit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testToStringReturnsPath()
public function test_getSuitesShouldReturnCorrectNumberOfSuites()
{
$suites = $this->config->getSuites();
$this->assertEquals(2, count($suites));
$this->assertCount(2, $suites);

return $suites;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Runners/PHPUnit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testFilteredOptionsShouldContainExtraneousOptions()

public function testAnnotationsReturnsAnnotations()
{
$this->assertEquals(1, count($this->options->annotations));
$this->assertCount(1, $this->options->annotations);
$this->assertEquals('group1', $this->options->annotations['group']);
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/Runners/PHPUnit/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testConstructorAssignsTokens()
$opts = ['processes' => 4, 'path' => FIXTURES . DS . 'tests', 'bootstrap' => 'hello', 'functional' => true];
$runner = new Runner($opts);
$tokens = $this->getObjectValue($runner, 'tokens');
$this->assertEquals(4, count($tokens));
$this->assertCount(4, $tokens);
}

public function testGetsNextAvailableTokenReturnsTokenIdentifier()
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testGetNextAvailableTokenReturnsFalseWhenNoTokensAreAvailable()
$this->setObjectValue($runner, 'tokens', $tokens);

$tokenData = $this->call($runner, 'getNextAvailableToken');
$this->assertTrue($tokenData === false);
$this->assertFalse($tokenData);
}

public function testReleaseTokenMakesTokenAvailable()
Expand Down
Loading

0 comments on commit 57eab83

Please sign in to comment.