1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'BeforeAndAfterTest.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'BeforeClassAndAfterClassTest.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'TestWithTest.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'BeforeClassWithOnlyDataProviderTest.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'DataProviderSkippedTest.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'DataProviderIncompleteTest.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'InheritedTestCase.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'NoTestCaseClass.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'NoTestCases.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'NotPublicTestCase.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'NotVoidTestCase.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'OverrideTestCase.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'RequirementsClassBeforeClassHookTest.php';
/**
* @since Class available since Release 2.0.0
* @covers PHPUnit_Framework_TestSuite
*/
class Framework_SuiteTest extends PHPUnit_Framework_TestCase
{
protected $result;
protected function setUp()
{
$this->result = new PHPUnit_Framework_TestResult;
}
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite;
$suite->addTest(new self('testAddTestSuite'));
$suite->addTest(new self('testInheritedTests'));
$suite->addTest(new self('testNoTestCases'));
$suite->addTest(new self('testNoTestCaseClass'));
$suite->addTest(new self('testNotExistingTestCase'));
$suite->addTest(new self('testNotPublicTestCase'));
$suite->addTest(new self('testNotVoidTestCase'));
$suite->addTest(new self('testOneTestCase'));
$suite->addTest(new self('testShadowedTests'));
$suite->addTest(new self('testBeforeClassAndAfterClassAnnotations'));
$suite->addTest(new self('testBeforeClassWithDataProviders'));
$suite->addTest(new self('testBeforeAnnotation'));
$suite->addTest(new self('testTestWithAnnotation'));
$suite->addTest(new self('testSkippedTestDataProvider'));
$suite->addTest(new self('testIncompleteTestDataProvider'));
$suite->addTest(new self('testRequirementsBeforeClassHook'));
$suite->addTest(new self('testDontSkipInheritedClass'));
return $suite;
}
public function testAddTestSuite()
{
$suite = new PHPUnit_Framework_TestSuite(
'OneTestCase'
);
$suite->run($this->result);
$this->assertEquals(1, count($this->result));
}
public function testInheritedTests()
{
$suite = new PHPUnit_Framework_TestSuite(
'InheritedTestCase'
);
$suite->run($this->result);
$this->assertTrue($this->result->wasSuccessful());
$this->assertEquals(2, count($this->result));
}
public function testNoTestCases()
{
$suite = new PHPUnit_Framework_TestSuite(
'NoTestCases'
);
$suite->run($this->result);
$this->assertTrue(!$this->result->wasSuccessful());
$this->assertEquals(0, $this->result->failureCount());
$this->assertEquals(1, $this->result->warningCount());
$this->assertEquals(1, count($this->result));
}
/**
* @expectedException PHPUnit_Framework_Exception
*/
public function testNoTestCaseClass()
{
$suite = new PHPUnit_Framework_TestSuite('NoTestCaseClass');
}
public function testNotExistingTestCase()
{
$suite = new self('notExistingMethod');
$suite->run($this->result);
$this->assertEquals(0, $this->result->errorCount());
$this->assertEquals(1, $this->result->failureCount());
$this->assertEquals(1, count($this->result));
}
public function testNotPublicTestCase()
{
$suite = new PHPUnit_Framework_TestSuite(
'NotPublicTestCase'
);
$this->assertEquals(2, count($suite));
}
public function testNotVoidTestCase()
{
$suite = new PHPUnit_Framework_TestSuite(
'NotVoidTestCase'
);
$this->assertEquals(1, count($suite));
}
public function testOneTestCase()
{
$suite = new PHPUnit_Framework_TestSuite(
'OneTestCase'
);
$suite->run($this->result);
$this->assertEquals(0, $this->result->errorCount());
$this->assertEquals(0, $this->result->failureCount());
$this->assertEquals(1, count($this->result));
$this->assertTrue($this->result->wasSuccessful());
}
public function testShadowedTests()
{
$suite = new PHPUnit_Framework_TestSuite(
'OverrideTestCase'
);
$suite->run($this->result);
$this->assertEquals(1, count($this->result));
}
public function testBeforeClassAndAfterClassAnnotations()
{
$suite = new PHPUnit_Framework_TestSuite(
'BeforeClassAndAfterClassTest'
);
BeforeClassAndAfterClassTest::resetProperties();
$suite->run($this->result);
$this->assertEquals(1, BeforeClassAndAfterClassTest::$beforeClassWasRun, '@beforeClass method was not run once for the whole suite.');
$this->assertEquals(1, BeforeClassAndAfterClassTest::$afterClassWasRun, '@afterClass method was not run once for the whole suite.');
}
public function testBeforeClassWithDataProviders()
{
$suite = new PHPUnit_Framework_TestSuite(
'BeforeClassWithOnlyDataProviderTest'
);
BeforeClassWithOnlyDataProviderTest::resetProperties();
$suite->run($this->result);
$this->assertTrue(BeforeClassWithOnlyDataProviderTest::$setUpBeforeClassWasCalled, 'setUpBeforeClass method was not run.');
$this->assertTrue(BeforeClassWithOnlyDataProviderTest::$beforeClassWasCalled, '@beforeClass method was not run.');
}
public function testBeforeAnnotation()
{
$test = new PHPUnit_Framework_TestSuite(
'BeforeAndAfterTest'
);
BeforeAndAfterTest::resetProperties();
$result = $test->run();
$this->assertEquals(2, BeforeAndAfterTest::$beforeWasRun);
$this->assertEquals(2, BeforeAndAfterTest::$afterWasRun);
}
public function testTestWithAnnotation()
{
$test = new PHPUnit_Framework_TestSuite(
'TestWithTest'
);
BeforeAndAfterTest::resetProperties();
$result = $test->run();
$this->assertEquals(4, count($result->passed()));
}
public function testSkippedTestDataProvider()
{
$suite = new PHPUnit_Framework_TestSuite('DataProviderSkippedTest');
$suite->run($this->result);
$this->assertEquals(3, $this->result->count());
$this->assertEquals(1, $this->result->skippedCount());
}
public function testIncompleteTestDataProvider()
{
$suite = new PHPUnit_Framework_TestSuite('DataProviderIncompleteTest');
$suite->run($this->result);
$this->assertEquals(3, $this->result->count());
$this->assertEquals(1, $this->result->notImplementedCount());
}
public function testRequirementsBeforeClassHook()
{
$suite = new PHPUnit_Framework_TestSuite(
'RequirementsClassBeforeClassHookTest'
);
$suite->run($this->result);
$this->assertEquals(0, $this->result->errorCount());
$this->assertEquals(1, $this->result->skippedCount());
}
public function testDontSkipInheritedClass()
{
$suite = new PHPUnit_Framework_TestSuite(
'DontSkipInheritedClass'
);
$dir = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Inheritance' . DIRECTORY_SEPARATOR;
$suite->addTestFile($dir . 'InheritanceA.php');
$suite->addTestFile($dir . 'InheritanceB.php');
$result = $suite->run();
$this->assertEquals(2, count($result));
}
}
|