updated packages

This commit is contained in:
2019-05-18 09:06:43 +00:00
parent 901d16349e
commit e9487fa58a
2025 changed files with 30366 additions and 49653 deletions
@@ -39,4 +39,17 @@ class DependencyFailureTest extends TestCase
{
$this->assertTrue(true);
}
/**
* This test has been added to check the printed warnings for the user
* when a dependency simply doesn't exist.
*
* @depends doesNotExist
*
* @see https://github.com/sebastianbergmann/phpunit/issues/3517
*/
public function testHandlesDependsAnnotationForNonexistentTests(): void
{
$this->assertTrue(true);
}
}
@@ -30,7 +30,7 @@ class ExceptionInTearDownTest extends TestCase
{
$this->tearDown = true;
throw new Exception;
throw new Exception('throw Exception in tearDown()');
}
public function testSomething(): void
@@ -9,4 +9,5 @@
*/
interface ExceptionWithThrowable extends \Throwable
{
public function getAdditionalInformation();
}
+7 -4
View File
@@ -7,11 +7,14 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
function functionCallback()
class FunctionCallbackWrapper
{
$args = \func_get_args();
public static function functionCallback()
{
$args = \func_get_args();
if ($args == ['foo', 'bar']) {
return 'pass';
if ($args == ['foo', 'bar']) {
return 'pass';
}
}
}
+11 -2
View File
@@ -72,6 +72,15 @@ class RequirementsTest extends TestCase
{
}
/**
* @requires function testFunc2
*
* @see https://github.com/sebastianbergmann/phpunit/issues/3459
*/
public function testRequiresFunctionWithDigit(): void
{
}
/**
* @requires extension testExt
*/
@@ -92,9 +101,9 @@ class RequirementsTest extends TestCase
* @requires PHPUnit 9-dev
* @requires OS DOESNOTEXIST
* @requires function testFuncOne
* @requires function testFuncTwo
* @requires function testFunc2
* @requires extension testExtOne
* @requires extension testExtTwo
* @requires extension testExt2
* @requires extension testExtThree 2.0
* @requires setting not_a_setting Off
*/
-39
View File
@@ -15,42 +15,3 @@ if (!\defined('TEST_FILES_PATH')) {
\ini_set('serialize_precision', 14);
require_once __DIR__ . '/../vendor/autoload.php';
// TODO: Figure out why these are required (the classes should be autoloaded instead)
require_once TEST_FILES_PATH . 'BeforeAndAfterTest.php';
require_once TEST_FILES_PATH . 'BeforeClassAndAfterClassTest.php';
require_once TEST_FILES_PATH . 'TestWithTest.php';
require_once TEST_FILES_PATH . 'BeforeClassWithOnlyDataProviderTest.php';
require_once TEST_FILES_PATH . 'DataProviderSkippedTest.php';
require_once TEST_FILES_PATH . 'DataProviderDependencyTest.php';
require_once TEST_FILES_PATH . 'DataProviderIncompleteTest.php';
require_once TEST_FILES_PATH . 'InheritedTestCase.php';
require_once TEST_FILES_PATH . 'NoTestCaseClass.php';
require_once TEST_FILES_PATH . 'NoTestCases.php';
require_once TEST_FILES_PATH . 'NotPublicTestCase.php';
require_once TEST_FILES_PATH . 'NotSelfDescribingTest.php';
require_once TEST_FILES_PATH . 'NotVoidTestCase.php';
require_once TEST_FILES_PATH . 'OverrideTestCase.php';
require_once TEST_FILES_PATH . 'RequirementsClassBeforeClassHookTest.php';
require_once TEST_FILES_PATH . 'NoArgTestCaseTest.php';
require_once TEST_FILES_PATH . 'Singleton.php';
require_once TEST_FILES_PATH . 'DoNoAssertionTestCase.php';
require_once TEST_FILES_PATH . 'FunctionCallback.php';
@@ -21,7 +21,7 @@ use PHPUnit\Runner\AfterTestWarningHook;
use PHPUnit\Runner\BeforeFirstTestHook;
use PHPUnit\Runner\BeforeTestHook;
final class Extension implements BeforeFirstTestHook, BeforeTestHook, AfterTestHook, AfterSuccessfulTestHook, AfterSkippedTestHook, AfterRiskyTestHook, AfterIncompleteTestHook, AfterTestErrorHook, AfterTestWarningHook, AfterTestFailureHook, AfterLastTestHook
final class Extension implements AfterIncompleteTestHook, AfterLastTestHook, AfterRiskyTestHook, AfterSkippedTestHook, AfterSuccessfulTestHook, AfterTestErrorHook, AfterTestFailureHook, AfterTestHook, AfterTestWarningHook, BeforeFirstTestHook, BeforeTestHook
{
private $amountOfInjectedArguments = 0;
@@ -0,0 +1,12 @@
--TEST--
Test incorrect testFile is reported
--ARGS--
--no-configuration tests nonExistingFile.php
--FILE--
<?php declare(strict_types=1);
require __DIR__ . '/../../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.
Cannot open file "nonExistingFile.php".
@@ -15,10 +15,17 @@ PHPUnit %s by Sebastian Bergmann and contributors.
Runtime: %s
...FSSS 7 / 7 (100%)
...FSSSW 8 / 8 (100%)
Time: %s, Memory: %s
There was 1 warning:
1) DependencyFailureTest::testHandlesDependsAnnotationForNonexistentTests
This test depends on "DependencyFailureTest::doesNotExist" which does not exist.
--
There was 1 failure:
1) DependencyFailureTest::testOne
@@ -39,4 +46,4 @@ This test depends on "DependencyFailureTest::testTwo" to pass.
This test depends on "DependencyFailureTest::testOne" to pass.
FAILURES!
Tests: 7, Assertions: 4, Failures: 1, Skipped: 3.
Tests: 8, Assertions: 4, Failures: 1, Warnings: 1, Skipped: 3.
+9 -2
View File
@@ -14,10 +14,17 @@ PHPUnit %s by Sebastian Bergmann and contributors.
Runtime: %s
...FSSS 7 / 7 (100%)
...FSSSW 8 / 8 (100%)
Time: %s, Memory: %s
There was 1 warning:
1) DependencyFailureTest::testHandlesDependsAnnotationForNonexistentTests
This test depends on "DependencyFailureTest::doesNotExist" which does not exist.
--
There was 1 failure:
1) DependencyFailureTest::testOne
@@ -38,4 +45,4 @@ This test depends on "DependencyFailureTest::testTwo" to pass.
This test depends on "DependencyFailureTest::testOne" to pass.
FAILURES!
Tests: 7, Assertions: 4, Failures: 1, Skipped: 3.
Tests: 8, Assertions: 4, Failures: 1, Warnings: 1, Skipped: 3.
@@ -16,6 +16,7 @@ require __DIR__ . '/../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.
<?php declare(strict_types=1);
if (!\function_exists('xdebug_set_filter')) {
return;
@@ -28,5 +29,4 @@ if (!\function_exists('xdebug_set_filter')) {
%s
]
);
Wrote Xdebug filter script to php://stderr
+9 -6
View File
@@ -3,18 +3,21 @@ phpunit --group balanceIsInitiallyZero BankAccountTest ../../_files/BankAccountT
--FILE--
<?php
$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--group';
$_SERVER['argv'][3] = 'balanceIsInitiallyZero';
$_SERVER['argv'][4] = 'BankAccountTest';
$_SERVER['argv'][5] = __DIR__ . '/../_files/BankAccountTest.php';
$_SERVER['argv'][2] = '--testdox';
$_SERVER['argv'][3] = '--group';
$_SERVER['argv'][4] = '3502';
$_SERVER['argv'][5] = 'NumericGroupAnnotationTest';
$_SERVER['argv'][6] = __DIR__ . '/../_files/NumericGroupAnnotationTest.php';
require __DIR__ . '/../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
NumericGroupAnnotation
✔ Empty test for @ticket numeric annotation values
✔ Empty test for @group numeric annotation values
Time: %s, Memory: %s
OK (1 test, 1 assertion)
OK (2 tests, 2 assertions)
@@ -49,12 +49,16 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, true
)
$__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, true
);
$__phpunit_invocation->setProxiedCall();
$this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation);
unset($__phpunit_invocation);
return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments);
}
@@ -71,12 +75,16 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'baz', $__phpunit_arguments, '', $this, true
)
$__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'baz', $__phpunit_arguments, '', $this, true
);
$__phpunit_invocation->setProxiedCall();
$this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation);
unset($__phpunit_invocation);
return call_user_func_array(array($this->__phpunit_originalObject, "baz"), $__phpunit_arguments);
}
@@ -35,11 +35,15 @@ print $code;
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, false
)
$__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, false
);
$__phpunit_invocation->setProxiedCall();
$this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation);
unset($__phpunit_invocation);
return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments);
}
@@ -35,11 +35,15 @@ private function bar($arg)
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, false
)
$__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, false
);
$__phpunit_invocation->setProxiedCall();
$this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation);
unset($__phpunit_invocation);
return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments);
}
@@ -35,11 +35,15 @@ private function bar(...$args)
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, false
)
$__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, '', $this, false
);
$__phpunit_invocation->setProxiedCall();
$this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation);
unset($__phpunit_invocation);
return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments);
}
@@ -35,11 +35,15 @@ print $code;
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, 'void', $this, false
)
$__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $__phpunit_arguments, 'void', $this, false
);
$__phpunit_invocation->setProxiedCall();
$this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation);
unset($__phpunit_invocation);
call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments);
}
@@ -1,2 +0,0 @@
.phpunit.result.cache
@@ -4,12 +4,11 @@ phpunit --random-order --random-order-seed=54321 --resolve-dependencies ../_file
<?php
$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--debug';
$_SERVER['argv'][3] = '--verbose';
$_SERVER['argv'][4] = '--random-order';
$_SERVER['argv'][5] = '--random-order-seed=54321';
$_SERVER['argv'][6] = '--resolve-dependencies';
$_SERVER['argv'][7] = 'MultiDependencyTest';
$_SERVER['argv'][8] = __DIR__ . '/../_files/MultiDependencyTest.php';
$_SERVER['argv'][3] = '--random-order';
$_SERVER['argv'][4] = '--random-order-seed=54321';
$_SERVER['argv'][5] = '--resolve-dependencies';
$_SERVER['argv'][6] = 'MultiDependencyTest';
$_SERVER['argv'][7] = __DIR__ . '/../_files/MultiDependencyTest.php';
require __DIR__ . '/../bootstrap.php';
PHPUnit\TextUI\Command::main();
@@ -17,7 +16,6 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.
Runtime: %s
Random seed: 54321
Test 'MultiDependencyTest::testTwo' started
@@ -966,6 +966,30 @@ XML;
$this->assertObjectHasAttribute('foo', $o);
}
public function testAssertObjectHasAttributeNumericAttribute(): void
{
$object = new \stdClass;
$object->{'2020'} = 'Tokyo';
$this->assertObjectHasAttribute('2020', $object);
$this->expectException(AssertionFailedError::class);
$this->assertObjectHasAttribute('2018', $object);
}
public function testAssertObjectHasAttributeMultiByteAttribute(): void
{
$object = new \stdClass;
$object->{'東京'} = 2020;
$this->assertObjectHasAttribute('東京', $object);
$this->expectException(AssertionFailedError::class);
$this->assertObjectHasAttribute('長野', $object);
}
public function testAssertObjectNotHasAttribute(): void
{
$o = new \Author('Terry Pratchett');
@@ -977,6 +1001,30 @@ XML;
$this->assertObjectNotHasAttribute('name', $o);
}
public function testAssertObjectNotHasAttributeNumericAttribute(): void
{
$object = new \stdClass;
$object->{'2020'} = 'Tokyo';
$this->assertObjectNotHasAttribute('2018', $object);
$this->expectException(AssertionFailedError::class);
$this->assertObjectNotHasAttribute('2020', $object);
}
public function testAssertObjectNotHasAttributeMultiByteAttribute(): void
{
$object = new \stdClass;
$object->{'東京'} = 2020;
$this->assertObjectNotHasAttribute('長野', $object);
$this->expectException(AssertionFailedError::class);
$this->assertObjectNotHasAttribute('東京', $object);
}
public function testAssertFinite(): void
{
$this->assertFinite(1);
@@ -3004,6 +3052,38 @@ XML;
$this->fail();
}
public function testIterableContainsSameObjectCanBeAsserted(): void
{
$object = new \stdClass;
$iterable = [$object];
$this->assertContains($object, $iterable);
try {
$this->assertContains(new \stdClass, $iterable);
} catch (AssertionFailedError $e) {
return;
}
$this->fail();
}
public function testIterableNotContainsSameObjectCanBeAsserted(): void
{
$object = new \stdClass;
$iterable = [$object];
$this->assertNotContains(new \stdClass, $iterable);
try {
$this->assertNotContains($object, $iterable);
} catch (AssertionFailedError $e) {
return;
}
$this->fail();
}
protected function sameValues(): array
{
$object = new \SampleClass(4, 8, 15);
@@ -36,7 +36,7 @@ abstract class ConstraintTestCase extends TestCase
$this->assertTrue($reflection->implementsInterface(SelfDescribing::class), \sprintf(
'Failed to assert that "%s" implements "%s".',
$className,
\Countable::class
SelfDescribing::class
));
}
@@ -13,43 +13,41 @@ use PHPUnit\Framework\TestCase;
class ExceptionMessageRegExpTest extends TestCase
{
/**
* @expectedException \Exception
* @expectedExceptionMessageRegExp /^A polymorphic \w+ message/
*/
public function testRegexMessage(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/^A polymorphic \w+ message/');
throw new \Exception('A polymorphic exception message');
}
/**
* @expectedException \Exception
* @expectedExceptionMessageRegExp /^a poly[a-z]+ [a-zA-Z0-9_]+ me(s){2}age$/i
*/
public function testRegexMessageExtreme(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/^a poly[a-z]+ [a-zA-Z0-9_]+ me(s){2}age$/i');
throw new \Exception('A polymorphic exception message');
}
/**
* @runInSeparateProcess
* @requires extension xdebug
* @expectedException \Exception
* @expectedExceptionMessageRegExp #Screaming preg_match#
*/
public function testMessageXdebugScreamCompatibility(): void
{
\ini_set('xdebug.scream', '1');
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('#Screaming preg_match#');
throw new \Exception('Screaming preg_match');
}
/**
* @expectedException \Exception variadic
* @expectedExceptionMessageRegExp /^A variadic \w+ message/
*/
public function testSimultaneousLiteralAndRegExpExceptionMessage(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/^A variadic \w+ message/');
throw new \Exception('A variadic exception message');
}
}
@@ -13,39 +13,35 @@ use PHPUnit\Framework\TestCase;
class ExceptionMessageTest extends TestCase
{
/**
* @expectedException \Exception
* @expectedExceptionMessage A literal exception message
*/
public function testLiteralMessage(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('A literal exception message');
throw new \Exception('A literal exception message');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage A partial
*/
public function testPartialMessageBegin(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('A partial');
throw new \Exception('A partial exception message');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage partial exception
*/
public function testPartialMessageMiddle(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('partial exception');
throw new \Exception('A partial exception message');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage exception message
*/
public function testPartialMessageEnd(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('exception message');
throw new \Exception('A partial exception message');
}
}
@@ -17,15 +17,31 @@ class StringEndsWithTest extends ConstraintTestCase
public function testConstraintStringEndsWithCorrectValueAndReturnResult(): void
{
$constraint = new StringEndsWith('suffix');
$this->assertTrue($constraint->evaluate('foosuffix', '', true));
}
public function testConstraintStringEndsWithNotCorrectValueAndReturnResult(): void
{
$constraint = new StringEndsWith('suffix');
$this->assertFalse($constraint->evaluate('suffixerror', '', true));
}
public function testConstraintStringEndsWithCorrectNumericValueAndReturnResult(): void
{
$constraint = new StringEndsWith('0E1');
$this->assertTrue($constraint->evaluate('zzz0E1', '', true));
}
public function testConstraintStringEndsWithNotCorrectNumericValueAndReturnResult(): void
{
$constraint = new StringEndsWith('0E1');
$this->assertFalse($constraint->evaluate('zzz0E2', '', true));
}
public function testConstraintStringEndsWithToStringMethod(): void
{
$constraint = new StringEndsWith('suffix');
@@ -28,6 +28,20 @@ class StringStartsWithTest extends ConstraintTestCase
$this->assertFalse($constraint->evaluate('error', '', true));
}
public function testConstraintStringStartsWithCorrectNumericValueAndReturnResult(): void
{
$constraint = new StringStartsWith('0E1');
$this->assertTrue($constraint->evaluate('0E1zzz', '', true));
}
public function testConstraintStringStartsWithNotCorrectNumericValueAndReturnResult(): void
{
$constraint = new StringStartsWith('0E1');
$this->assertFalse($constraint->evaluate('0E2zzz', '', true));
}
public function testConstraintStringStartsWithToStringMethod(): void
{
$constraint = new StringStartsWith('prefix');
@@ -73,7 +87,8 @@ EOF
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<EOF
custom message\nFailed asserting that 'error' starts with "prefix".
custom message
Failed asserting that 'error' starts with "prefix".
EOF
,
@@ -202,7 +202,7 @@ class GeneratorTest extends TestCase
$this->assertNull($mock->someMethod());
}
public function testMockingOfThrowable(): void
public function testMockingOfExceptionWithThrowable(): void
{
$stub = $this->generator->getMock(ExceptionWithThrowable::class);
@@ -211,6 +211,15 @@ class GeneratorTest extends TestCase
$this->assertInstanceOf(MockObject::class, $stub);
}
public function testMockingOfThrowable(): void
{
$stub = $this->generator->getMock(Throwable::class);
$this->assertInstanceOf(Throwable::class, $stub);
$this->assertInstanceOf(Exception::class, $stub);
$this->assertInstanceOf(MockObject::class, $stub);
}
public function testVariadicArgumentsArePassedToOriginalMethod()
{
/** @var ClassWithVariadicArgumentMethod|MockObject $mock */
@@ -272,7 +272,7 @@ class MockObjectTest extends TestCase
$mock->expects($this->once())
->method('doSomething')
->will($this->returnCallback('functionCallback'));
->will($this->returnCallback('FunctionCallbackWrapper::functionCallback'));
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
@@ -282,7 +282,7 @@ class MockObjectTest extends TestCase
$mock->expects($this->once())
->method('doSomething')
->willReturnCallback('functionCallback');
->willReturnCallback('FunctionCallbackWrapper::functionCallback');
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
}
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
@@ -8,34 +8,86 @@
* file that was distributed with this source code.
*/
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class ProxyObjectTest extends TestCase
final class ProxyObjectTest extends TestCase
{
public function testMockedMethodIsProxiedToOriginalMethod(): void
public function testProxyingWorksForMethodThatReturnsUndeclaredScalarValue(): void
{
$proxy = $this->getMockBuilder(Bar::class)
->enableProxyingToOriginalMethods()
->getMock();
$proxy = $this->createTestProxy(TestProxyFixture::class);
$proxy->expects($this->once())
->method('doSomethingElse');
->method('returnString');
$foo = new Foo;
\assert($proxy instanceof MockObject);
\assert($proxy instanceof TestProxyFixture);
$this->assertEquals('result', $foo->doSomething($proxy));
$this->assertSame('result', $proxy->returnString());
}
public function testMockedMethodWithReferenceIsProxiedToOriginalMethod(): void
public function testProxyingWorksForMethodThatReturnsDeclaredScalarValue(): void
{
$proxy = $this->getMockBuilder(MethodCallbackByReference::class)
->enableProxyingToOriginalMethods()
->getMock();
$proxy = $this->createTestProxy(TestProxyFixture::class);
$a = $b = $c = 0;
$proxy->expects($this->once())
->method('returnTypedString');
$proxy->callback($a, $b, $c);
\assert($proxy instanceof MockObject);
\assert($proxy instanceof TestProxyFixture);
$this->assertEquals(1, $b);
$this->assertSame('result', $proxy->returnTypedString());
}
public function testProxyingWorksForMethodThatReturnsUndeclaredObject(): void
{
$proxy = $this->createTestProxy(TestProxyFixture::class);
$proxy->expects($this->once())
->method('returnObject');
\assert($proxy instanceof MockObject);
\assert($proxy instanceof TestProxyFixture);
$this->assertSame('bar', $proxy->returnObject()->foo);
}
public function testProxyingWorksForMethodThatReturnsDeclaredObject(): void
{
$proxy = $this->createTestProxy(TestProxyFixture::class);
$proxy->expects($this->once())
->method('returnTypedObject');
\assert($proxy instanceof MockObject);
\assert($proxy instanceof TestProxyFixture);
$this->assertSame('bar', $proxy->returnTypedObject()->foo);
}
public function testProxyingWorksForMethodThatReturnsUndeclaredObjectOfFinalClass(): void
{
$proxy = $this->createTestProxy(TestProxyFixture::class);
$proxy->expects($this->once())
->method('returnObjectOfFinalClass');
\assert($proxy instanceof MockObject);
\assert($proxy instanceof TestProxyFixture);
$this->assertSame('value', $proxy->returnObjectOfFinalClass()->value());
}
public function testProxyingWorksForMethodThatReturnsDeclaredObjectOfFinalClass(): void
{
$proxy = $this->createTestProxy(TestProxyFixture::class);
$proxy->expects($this->once())
->method('returnTypedObjectOfFinalClass');
\assert($proxy instanceof MockObject);
\assert($proxy instanceof TestProxyFixture);
$this->assertSame('value', $proxy->returnTypedObjectOfFinalClass()->value());
}
}
@@ -14,7 +14,7 @@ use PHPUnit\Runner\BaseTestRunner;
class TestCaseTest extends TestCase
{
protected static $testStatic = 0;
protected static $testStatic = 456;
protected $backupGlobalsBlacklist = ['i', 'singleton'];
@@ -175,6 +175,7 @@ class TestCaseTest extends TestCase
$this->assertTrue($test->assertPostConditions);
$this->assertTrue($test->tearDown);
$this->assertEquals(BaseTestRunner::STATUS_ERROR, $test->getStatus());
$this->assertSame('throw Exception in tearDown()', $test->getStatusMessage());
}
public function testExceptionInTestIsDetectedInTeardown(): void
@@ -418,6 +419,9 @@ class TestCaseTest extends TestCase
public function testStaticAttributesBackupPre(): void
{
$GLOBALS['singleton'] = \Singleton::getInstance();
$GLOBALS['i'] = 'not reset by backup';
$GLOBALS['j'] = 'reset by backup';
self::$testStatic = 123;
}
@@ -426,8 +430,15 @@ class TestCaseTest extends TestCase
*/
public function testStaticAttributesBackupPost(): void
{
$this->assertNotSame($GLOBALS['singleton'], \Singleton::getInstance());
$this->assertSame(0, self::$testStatic);
// Snapshots made by @backupGlobals
$this->assertSame(\Singleton::getInstance(), $GLOBALS['singleton']);
$this->assertSame('not reset by backup', $GLOBALS['i']);
// Reset global
$this->assertArrayNotHasKey('j', $GLOBALS);
// Static reset to original state by @backupStaticAttributes
$this->assertSame(456, self::$testStatic);
}
public function testIsInIsolationReturnsFalse(): void
@@ -577,10 +588,10 @@ class TestCaseTest extends TestCase
'PHPUnit >= 9-dev is required.' . \PHP_EOL .
'Operating system matching /DOESNOTEXIST/i is required.' . \PHP_EOL .
'Function testFuncOne is required.' . \PHP_EOL .
'Function testFuncTwo is required.' . \PHP_EOL .
'Function testFunc2 is required.' . \PHP_EOL .
'Setting "not_a_setting" must be "Off".' . \PHP_EOL .
'Extension testExtOne is required.' . \PHP_EOL .
'Extension testExtTwo is required.' . \PHP_EOL .
'Extension testExt2 is required.' . \PHP_EOL .
'Extension testExtThree >= 2.0 is required.',
$test->getStatusMessage()
);
@@ -644,11 +655,13 @@ class TestCaseTest extends TestCase
/**
* @requires PHP 7
* @expectedException \TypeError
*/
public function testTypeErrorCanBeExpected(): void
{
$o = new \ClassWithScalarTypeDeclarations;
$this->expectException(\TypeError::class);
$o->foo(null, null);
}
+36 -11
View File
@@ -26,6 +26,18 @@ class TestSuiteTest extends TestCase
$this->result = null;
}
/**
* @testdox TestSuite can be created with name of existing non-TestCase class
*/
public function testSuiteNameCanBeSameAsExistingNonTestClassName(): void
{
$suite = new TestSuite('stdClass');
$suite->addTestSuite(\OneTestCase::class);
$suite->run($this->result);
$this->assertCount(1, $this->result);
}
public function testAddTestSuite(): void
{
$suite = new TestSuite(\OneTestCase::class);
@@ -57,13 +69,6 @@ class TestSuiteTest extends TestCase
$this->assertCount(1, $this->result);
}
public function testNoTestCaseClass(): void
{
$this->expectException(Exception::class);
new TestSuite(\NoTestCaseClass::class);
}
public function testNotPublicTestCase(): void
{
$suite = new TestSuite(\NotPublicTestCase::class);
@@ -201,10 +206,6 @@ class TestSuiteTest extends TestCase
$this->assertCount(2, $result);
}
/**
* @expectedException PHPUnit\Framework\Exception
* @expectedExceptionMessage No valid test provided.
*/
public function testCreateTestForConstructorlessTestClass(): void
{
$reflection = $this->getMockBuilder(\ReflectionClass::class)
@@ -220,6 +221,30 @@ class TestSuiteTest extends TestCase
$reflection->expects($this->once())
->method('getName')
->willReturn(__CLASS__);
$this->expectException(Exception::class);
$this->expectExceptionMessage('No valid test provided.');
TestSuite::createTest($reflection, 'TestForConstructorlessTestClass');
}
/**
* @testdox Handles exceptions in tearDownAfterClass()
*/
public function testTearDownAfterClassInTestSuite(): void
{
$suite = new TestSuite(\ExceptionInTearDownAfterClassTest::class);
$suite->run($this->result);
$this->assertSame(3, $this->result->count());
$this->assertCount(1, $this->result->failures());
$failure = $this->result->failures()[0];
$this->assertSame(
'Exception in ExceptionInTearDownAfterClassTest::tearDownAfterClass' . \PHP_EOL .
'throw Exception in tearDownAfterClass()',
$failure->thrownException()->getMessage()
);
}
}
+34 -15
View File
@@ -208,39 +208,38 @@ EOF
$this->testCase->run();
}
public function testShouldThrowsAnExceptionWhenPhptFileIsEmpty(): void
public function testShouldSkipTestWhenPhptFileIsEmpty(): void
{
$this->setPhpContent('');
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid PHPT file');
$this->testCase->run();
$result = $this->testCase->run();
$this->assertCount(1, $result->skipped());
$this->assertSame('Invalid PHPT file', $result->skipped()[0]->thrownException()->getMessage());
}
public function testShouldThrowsAnExceptionWhenFileSectionIsMissing(): void
public function testShouldSkipTestWhenFileSectionIsMissing(): void
{
$this->setPhpContent(
<<<EOF
--TEST--
Something to decribe it
Something to describe it
--EXPECT--
Something
EOF
);
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid PHPT file');
$result = $this->testCase->run();
$this->testCase->run();
$this->assertCount(1, $result->skipped());
$this->assertSame('Invalid PHPT file', $result->skipped()[0]->thrownException()->getMessage());
}
public function testShouldThrowsAnExceptionWhenThereIsNoExpecOrExpectifOrExpecregexSectionInPhptFile(): void
public function testShouldSkipTestWhenThereIsNoExpecOrExpectifOrExpecregexSectionInPhptFile(): void
{
$this->setPhpContent(
<<<EOF
--TEST--
Something to decribe it
Something to describe it
--FILE--
<?php
echo "Hello world!\n";
@@ -248,10 +247,30 @@ echo "Hello world!\n";
EOF
);
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid PHPT file');
$result = $this->testCase->run();
$this->testCase->run();
$this->assertCount(1, $result->skipped());
$skipMessage = $result->skipped()[0]->thrownException()->getMessage();
$this->assertSame('Invalid PHPT file', $skipMessage);
}
public function testShouldSkipTestWhenSectionHeaderIsMalformed(): void
{
$this->setPhpContent(
<<<EOF
----
--TEST--
This is not going to work out
--EXPECT--
Tears and misery
EOF
);
$result = $this->testCase->run();
$this->assertCount(1, $result->skipped());
$skipMessage = $result->skipped()[0]->thrownException()->getMessage();
$this->assertSame('Invalid PHPT file: empty section header', $skipMessage);
}
public function testShouldValidateExpectSession(): void
+4 -2
View File
@@ -9,6 +9,7 @@
*/
namespace PHPUnit\Util;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
class JsonTest extends TestCase
@@ -60,11 +61,12 @@ class JsonTest extends TestCase
/**
* @dataProvider prettifyExceptionProvider
* @expectedException \PHPUnit\Framework\Exception
* @expectedExceptionMessage Cannot prettify invalid json
*/
public function testPrettifyException($json): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('Cannot prettify invalid json');
Json::prettify($json);
}
+4 -4
View File
@@ -157,14 +157,14 @@ class TestTest extends TestCase
'OS' => 'DOESNOTEXIST',
'functions' => [
'testFuncOne',
'testFuncTwo',
'testFunc2',
],
'setting' => [
'not_a_setting' => 'Off',
],
'extensions' => [
'testExtOne',
'testExtTwo',
'testExt2',
'testExtThree',
],
'extension_versions' => [
@@ -526,10 +526,10 @@ class TestTest extends TestCase
'PHPUnit >= 9-dev is required.',
'Operating system matching /DOESNOTEXIST/i is required.',
'Function testFuncOne is required.',
'Function testFuncTwo is required.',
'Function testFunc2 is required.',
'Setting "not_a_setting" must be "Off".',
'Extension testExtOne is required.',
'Extension testExtTwo is required.',
'Extension testExt2 is required.',
'Extension testExtThree >= 2.0 is required.',
]],
['testPHPVersionOperatorLessThan', ['PHP < 5.4 is required.']],
@@ -18,11 +18,50 @@ class XDebugFilterScriptGeneratorTest extends TestCase
*/
public function testReturnsExpectedScript(): void
{
$expectedDirectory = \sprintf('%s/', __DIR__);
$expected = <<<EOF
<?php declare(strict_types=1);
if (!\\function_exists('xdebug_set_filter')) {
return;
}
\\xdebug_set_filter(
\\XDEBUG_FILTER_CODE_COVERAGE,
\\XDEBUG_PATH_WHITELIST,
[
'$expectedDirectory',
'$expectedDirectory',
'$expectedDirectory',
'src/foo.php',
'src/bar.php'
]
);
EOF;
$directoryPathThatDoesNotExist = \sprintf('%s/path/that/does/not/exist', __DIR__);
$this->assertDirectoryNotExists($directoryPathThatDoesNotExist);
$filterConfiguration = [
'include' => [
'directory' => [
[
'path' => 'src/somePath',
'path' => __DIR__,
'suffix' => '.php',
'prefix' => '',
],
[
'path' => \sprintf('%s/', __DIR__),
'suffix' => '.php',
'prefix' => '',
],
[
'path' => \sprintf('%s/./%s', \dirname(__DIR__), \basename(__DIR__)),
'suffix' => '.php',
'prefix' => '',
],
[
'path' => $directoryPathThatDoesNotExist,
'suffix' => '.php',
'prefix' => '',
],
@@ -41,6 +80,6 @@ class XDebugFilterScriptGeneratorTest extends TestCase
$writer = new XdebugFilterScriptGenerator;
$actual = $writer->generate($filterConfiguration);
$this->assertStringEqualsFile(__DIR__ . '/_files/expectedXDebugFilterScript.txt', $actual);
$this->assertSame($expected, $actual);
}
}
@@ -1,14 +0,0 @@
<?php declare(strict_types=1);
if (!\function_exists('xdebug_set_filter')) {
return;
}
\xdebug_set_filter(
\XDEBUG_FILTER_CODE_COVERAGE,
\XDEBUG_PATH_WHITELIST,
[
'src/somePath',
'src/foo.php',
'src/bar.php'
]
);