Skip to content

Commit

Permalink
Fix not failing for tests using data providers
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
oradwell committed May 8, 2018
1 parent af86682 commit 1401997
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Command/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$testClass = get_class($suite);
$testMethod = $suite->getName();
$testSignature = $testClass . '::' . $testMethod;
$testMethod = $suite->getName(false);
$testSignature = $testClass . '::' . $suite->getName();

if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
$this->writeValidity($output, 'Validating ' . $testSignature . '...');
Expand Down
31 changes: 31 additions & 0 deletions tests/Command/ValidateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ public function testReturnsFailForEmptyCoversTag()
$this->assertRegExp('/There were 1 test\(s\) with invalid @covers tags./', $display);
}

public function testReturnsFailForInvalidCoversTagWithProvider()
{
$app = new CoversValidator;
/** @var ValidateCommand $command */
$command = $app->find('validate');
$commandTester = new CommandTester($command);
$exitCode = $commandTester->execute(array(
'-c' => 'tests/Fixtures/configuration-nonexistentprovider.xml'
));

$this->assertGreaterThan(0, $exitCode);
$display = $commandTester->getDisplay();
$this->assertRegExp('/Invalid - /', $display);
$this->assertRegExp('/There were 1 test\(s\) with invalid @covers tags./', $display);
}

public function testReturnsSuccessForExistingClasses()
{
$app = new CoversValidator;
Expand All @@ -116,6 +132,21 @@ public function testReturnsSuccessForExistingClasses()
$this->assertRegExp('/Validating /', $display);
}

public function testReturnsSuccessForValidCoversTagWithProvider()
{
$app = new CoversValidator;
/** @var ValidateCommand $command */
$command = $app->find('validate');
$commandTester = new CommandTester($command);
$exitCode = $commandTester->execute(array(
'-c' => 'tests/Fixtures/configuration-existingprovider.xml'
));

$this->assertSame(0, $exitCode);
$display = $commandTester->getDisplay();
$this->assertRegExp('/Validation complete. All @covers tags are valid./', $display);
}

public function testReturnsFailForComboClasses()
{
$app = new CoversValidator;
Expand Down
20 changes: 20 additions & 0 deletions tests/Fixtures/OneTestWithProviderCoveringExistingClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace OckCyp\CoversValidator\Tests\Fixtures;

class OneTestWithProviderCoveringExistingClassTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers OckCyp\CoversValidator\Tests\Fixtures\ExistingClass::existingMethod
* @dataProvider provideDummyTest
*/
public function testDummyTest()
{

}

public function provideDummyTest()
{

}
}
20 changes: 20 additions & 0 deletions tests/Fixtures/OneTestWithProviderCoveringNonExistentClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace OckCyp\CoversValidator\Tests\Fixtures;

class OneTestWithProviderCoveringNonExistentClassTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers OckCyp\CoversValidator\Tests\Fixtures\ExistingClass::nonExistingMethod
* @dataProvider provideDummyTest
*/
public function testDummyTest($x)
{

}

public function provideDummyTest()
{
return [['x']];
}
}
8 changes: 8 additions & 0 deletions tests/Fixtures/configuration-existingprovider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuites>
<testsuite name="My Test Suite">
<file>./OneTestWithProviderCoveringExistingClassTest.php</file>
</testsuite>
</testsuites>
</phpunit>
8 changes: 8 additions & 0 deletions tests/Fixtures/configuration-nonexistentprovider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuites>
<testsuite name="My Test Suite">
<file>./OneTestWithProviderCoveringNonExistentClassTest.php</file>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 1401997

Please sign in to comment.