Best Phpunit code snippet using AssertionFailedError
AssertTest.php
Source:AssertTest.php
...21 public function testFail(): void22 {23 try {24 $this->fail();25 } catch (AssertionFailedError $e) {26 return;27 }28 throw new AssertionFailedError('Fail did not throw fail exception');29 }30 public function testAssertSplObjectStorageContainsObject(): void31 {32 $a = new \stdClass;33 $b = new \stdClass;34 $c = new \SplObjectStorage;35 $c->attach($a);36 $this->assertContains($a, $c);37 $this->expectException(AssertionFailedError::class);38 $this->assertContains($b, $c);39 }40 public function testAssertArrayContainsObject(): void41 {42 $a = new \stdClass;43 $b = new \stdClass;44 $this->assertContains($a, [$a]);45 $this->expectException(AssertionFailedError::class);46 $this->assertContains($a, [$b]);47 }48 public function testAssertArrayContainsString(): void49 {50 $this->assertContains('foo', ['foo']);51 $this->expectException(AssertionFailedError::class);52 $this->assertContains('foo', ['bar']);53 }54 public function testAssertArrayContainsNonObject(): void55 {56 $this->assertContains('foo', [true]);57 $this->expectException(AssertionFailedError::class);58 $this->assertContains('foo', [true], '', false, true, true);59 }60 public function testAssertContainsOnlyInstancesOf(): void61 {62 $test = [new \Book, new \Book];63 $this->assertContainsOnlyInstancesOf(\Book::class, $test);64 $this->assertContainsOnlyInstancesOf(\stdClass::class, [new \stdClass]);65 $test2 = [new \Author('Test')];66 $this->expectException(AssertionFailedError::class);67 $this->assertContainsOnlyInstancesOf(\Book::class, $test2);68 }69 public function testAssertContainsPartialStringInString(): void70 {71 $this->assertContains('bar', 'foo bar');72 $this->expectException(AssertionFailedError::class);73 $this->assertContains('cake', 'foo bar');74 }75 public function testAssertContainsNonCaseSensitiveStringInString(): void76 {77 $this->assertContains('Foo', 'foo', '', true);78 $this->expectException(AssertionFailedError::class);79 $this->assertContains('Foo', 'foo', '', false);80 }81 public function testAssertContainsEmptyStringInString(): void82 {83 $this->assertContains('', 'test');84 }85 public function testAssertStringContainsNonString(): void86 {87 $this->expectException(Exception::class);88 $this->assertContains(null, '');89 }90 public function testAssertStringNotContainsNonString(): void91 {92 $this->expectException(Exception::class);93 $this->assertNotContains(null, '');94 }95 public function testAssertArrayHasKeyThrowsExceptionForInvalidFirstArgument(): void96 {97 $this->expectException(Exception::class);98 $this->assertArrayHasKey(null, []);99 }100 public function testAssertArrayHasKeyThrowsExceptionForInvalidSecondArgument(): void101 {102 $this->expectException(Exception::class);103 $this->assertArrayHasKey(0, null);104 }105 public function testAssertArrayHasIntegerKey(): void106 {107 $this->assertArrayHasKey(0, ['foo']);108 $this->expectException(AssertionFailedError::class);109 $this->assertArrayHasKey(1, ['foo']);110 }111 public function testAssertArraySubset(): void112 {113 $array = [114 'a' => 'item a',115 'b' => 'item b',116 'c' => ['a2' => 'item a2', 'b2' => 'item b2'],117 'd' => ['a2' => ['a3' => 'item a3', 'b3' => 'item b3']],118 ];119 $this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $array);120 $this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $array);121 $arrayAccessData = new \ArrayObject($array);122 $this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $arrayAccessData);123 $this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $arrayAccessData);124 try {125 $this->assertArraySubset(['a' => 'bad value'], $array);126 } catch (AssertionFailedError $e) {127 }128 try {129 $this->assertArraySubset(['d' => ['a2' => ['bad index' => 'item b3']]], $array);130 } catch (AssertionFailedError $e) {131 return;132 }133 $this->fail();134 }135 public function testAssertArraySubsetWithDeepNestedArrays(): void136 {137 $array = [138 'path' => [139 'to' => [140 'the' => [141 'cake' => 'is a lie',142 ],143 ],144 ],145 ];146 $this->assertArraySubset(['path' => []], $array);147 $this->assertArraySubset(['path' => ['to' => []]], $array);148 $this->assertArraySubset(['path' => ['to' => ['the' => []]]], $array);149 $this->assertArraySubset(['path' => ['to' => ['the' => ['cake' => 'is a lie']]]], $array);150 $this->expectException(AssertionFailedError::class);151 $this->assertArraySubset(['path' => ['to' => ['the' => ['cake' => 'is not a lie']]]], $array);152 }153 public function testAssertArraySubsetWithNoStrictCheckAndObjects(): void154 {155 $obj = new \stdClass;156 $reference = &$obj;157 $array = ['a' => $obj];158 $this->assertArraySubset(['a' => $reference], $array);159 $this->assertArraySubset(['a' => new \stdClass], $array);160 }161 public function testAssertArraySubsetWithStrictCheckAndObjects(): void162 {163 $obj = new \stdClass;164 $reference = &$obj;165 $array = ['a' => $obj];166 $this->assertArraySubset(['a' => $reference], $array, true);167 $this->expectException(AssertionFailedError::class);168 $this->assertArraySubset(['a' => new \stdClass], $array, true);169 }170 /**171 * @dataProvider assertArraySubsetInvalidArgumentProvider172 *173 * @throws Exception174 * @throws ExpectationFailedException175 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException176 */177 public function testAssertArraySubsetRaisesExceptionForInvalidArguments($partial, $subject): void178 {179 $this->expectException(Exception::class);180 $this->assertArraySubset($partial, $subject);181 }182 public function assertArraySubsetInvalidArgumentProvider(): array183 {184 return [185 [false, []],186 [[], false],187 ];188 }189 public function testAssertArrayNotHasKeyThrowsExceptionForInvalidFirstArgument(): void190 {191 $this->expectException(Exception::class);192 $this->assertArrayNotHasKey(null, []);193 }194 public function testAssertArrayNotHasKeyThrowsExceptionForInvalidSecondArgument(): void195 {196 $this->expectException(Exception::class);197 $this->assertArrayNotHasKey(0, null);198 }199 public function testAssertArrayNotHasIntegerKey(): void200 {201 $this->assertArrayNotHasKey(1, ['foo']);202 $this->expectException(AssertionFailedError::class);203 $this->assertArrayNotHasKey(0, ['foo']);204 }205 public function testAssertArrayHasStringKey(): void206 {207 $this->assertArrayHasKey('foo', ['foo' => 'bar']);208 $this->expectException(AssertionFailedError::class);209 $this->assertArrayHasKey('bar', ['foo' => 'bar']);210 }211 public function testAssertArrayNotHasStringKey(): void212 {213 $this->assertArrayNotHasKey('bar', ['foo' => 'bar']);214 $this->expectException(AssertionFailedError::class);215 $this->assertArrayNotHasKey('foo', ['foo' => 'bar']);216 }217 public function testAssertArrayHasKeyAcceptsArrayObjectValue(): void218 {219 $array = new \ArrayObject;220 $array['foo'] = 'bar';221 $this->assertArrayHasKey('foo', $array);222 }223 public function testAssertArrayHasKeyProperlyFailsWithArrayObjectValue(): void224 {225 $array = new \ArrayObject;226 $array['bar'] = 'bar';227 $this->expectException(AssertionFailedError::class);228 $this->assertArrayHasKey('foo', $array);229 }230 public function testAssertArrayHasKeyAcceptsArrayAccessValue(): void231 {232 $array = new \SampleArrayAccess;233 $array['foo'] = 'bar';234 $this->assertArrayHasKey('foo', $array);235 }236 public function testAssertArrayHasKeyProperlyFailsWithArrayAccessValue(): void237 {238 $array = new \SampleArrayAccess;239 $array['bar'] = 'bar';240 $this->expectException(AssertionFailedError::class);241 $this->assertArrayHasKey('foo', $array);242 }243 public function testAssertArrayNotHasKeyAcceptsArrayAccessValue(): void244 {245 $array = new \ArrayObject;246 $array['foo'] = 'bar';247 $this->assertArrayNotHasKey('bar', $array);248 }249 public function testAssertArrayNotHasKeyPropertlyFailsWithArrayAccessValue(): void250 {251 $array = new \ArrayObject;252 $array['bar'] = 'bar';253 $this->expectException(AssertionFailedError::class);254 $this->assertArrayNotHasKey('bar', $array);255 }256 public function testAssertContainsThrowsException(): void257 {258 $this->expectException(Exception::class);259 $this->assertContains(null, null);260 }261 public function testAssertIteratorContainsObject(): void262 {263 $foo = new \stdClass;264 $this->assertContains($foo, new \TestIterator([$foo]));265 $this->expectException(AssertionFailedError::class);266 $this->assertContains($foo, new \TestIterator([new \stdClass]));267 }268 public function testAssertIteratorContainsString(): void269 {270 $this->assertContains('foo', new \TestIterator(['foo']));271 $this->expectException(AssertionFailedError::class);272 $this->assertContains('foo', new \TestIterator(['bar']));273 }274 public function testAssertStringContainsString(): void275 {276 $this->assertContains('foo', 'foobar');277 $this->expectException(AssertionFailedError::class);278 $this->assertContains('foo', 'bar');279 }280 public function testAssertStringContainsStringForUtf8(): void281 {282 $this->assertContains('oryginaÅ', 'oryginaÅ');283 $this->expectException(AssertionFailedError::class);284 $this->assertContains('ORYGINAÅ', 'oryginaÅ');285 }286 public function testAssertStringContainsStringForUtf8WhenIgnoreCase(): void287 {288 $this->assertContains('oryginaÅ', 'oryginaÅ', '', true);289 $this->assertContains('ORYGINAÅ', 'oryginaÅ', '', true);290 $this->expectException(AssertionFailedError::class);291 $this->assertContains('foo', 'oryginaÅ', '', true);292 }293 public function testAssertNotContainsThrowsException(): void294 {295 $this->expectException(Exception::class);296 $this->assertNotContains(null, null);297 }298 public function testAssertSplObjectStorageNotContainsObject(): void299 {300 $a = new \stdClass;301 $b = new \stdClass;302 $c = new \SplObjectStorage;303 $c->attach($a);304 $this->assertNotContains($b, $c);305 $this->expectException(AssertionFailedError::class);306 $this->assertNotContains($a, $c);307 }308 public function testAssertArrayNotContainsObject(): void309 {310 $a = new \stdClass;311 $b = new \stdClass;312 $this->assertNotContains($a, [$b]);313 $this->expectException(AssertionFailedError::class);314 $this->assertNotContains($a, [$a]);315 }316 public function testAssertArrayNotContainsString(): void317 {318 $this->assertNotContains('foo', ['bar']);319 $this->expectException(AssertionFailedError::class);320 $this->assertNotContains('foo', ['foo']);321 }322 public function testAssertArrayNotContainsNonObject(): void323 {324 $this->assertNotContains('foo', [true], '', false, true, true);325 $this->expectException(AssertionFailedError::class);326 $this->assertNotContains('foo', [true]);327 }328 public function testAssertStringNotContainsString(): void329 {330 $this->assertNotContains('foo', 'bar');331 $this->expectException(AssertionFailedError::class);332 $this->assertNotContains('foo', 'foo');333 }334 public function testAssertStringNotContainsStringForUtf8(): void335 {336 $this->assertNotContains('ORYGINAÅ', 'oryginaÅ');337 $this->expectException(AssertionFailedError::class);338 $this->assertNotContains('oryginaÅ', 'oryginaÅ');339 }340 public function testAssertStringNotContainsStringForUtf8WhenIgnoreCase(): void341 {342 $this->expectException(AssertionFailedError::class);343 $this->assertNotContains('ORYGINAÅ', 'oryginaÅ', '', true);344 }345 public function testAssertArrayContainsOnlyIntegers(): void346 {347 $this->assertContainsOnly('integer', [1, 2, 3]);348 $this->expectException(AssertionFailedError::class);349 $this->assertContainsOnly('integer', ['1', 2, 3]);350 }351 public function testAssertArrayNotContainsOnlyIntegers(): void352 {353 $this->assertNotContainsOnly('integer', ['1', 2, 3]);354 $this->expectException(AssertionFailedError::class);355 $this->assertNotContainsOnly('integer', [1, 2, 3]);356 }357 public function testAssertArrayContainsOnlyStdClass(): void358 {359 $this->assertContainsOnly('StdClass', [new \stdClass]);360 $this->expectException(AssertionFailedError::class);361 $this->assertContainsOnly('StdClass', ['StdClass']);362 }363 public function testAssertArrayNotContainsOnlyStdClass(): void364 {365 $this->assertNotContainsOnly('StdClass', ['StdClass']);366 $this->expectException(AssertionFailedError::class);367 $this->assertNotContainsOnly('StdClass', [new \stdClass]);368 }369 public function equalProvider(): array370 {371 // same |= equal372 return \array_merge($this->equalValues(), $this->sameValues());373 }374 public function notEqualProvider()375 {376 return $this->notEqualValues();377 }378 public function sameProvider(): array379 {380 return $this->sameValues();381 }382 public function notSameProvider(): array383 {384 // not equal |= not same385 // equal, ¬same |= not same386 return \array_merge($this->notEqualValues(), $this->equalValues());387 }388 /**389 * @dataProvider equalProvider390 *391 * @throws ExpectationFailedException392 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException393 */394 public function testAssertEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void395 {396 $this->assertEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);397 }398 /**399 * @dataProvider notEqualProvider400 *401 * @throws ExpectationFailedException402 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException403 */404 public function testAssertEqualsFails($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void405 {406 $this->expectException(AssertionFailedError::class);407 $this->assertEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);408 }409 /**410 * @dataProvider notEqualProvider411 *412 * @throws ExpectationFailedException413 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException414 */415 public function testAssertNotEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void416 {417 $this->assertNotEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);418 }419 /**420 * @dataProvider equalProvider421 *422 * @throws ExpectationFailedException423 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException424 */425 public function testAssertNotEqualsFails($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void426 {427 $this->expectException(AssertionFailedError::class);428 $this->assertNotEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);429 }430 /**431 * @dataProvider sameProvider432 *433 * @throws ExpectationFailedException434 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException435 */436 public function testAssertSameSucceeds($a, $b): void437 {438 $this->assertSame($a, $b);439 }440 /**441 * @dataProvider notSameProvider442 *443 * @throws ExpectationFailedException444 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException445 */446 public function testAssertSameFails($a, $b): void447 {448 $this->expectException(AssertionFailedError::class);449 $this->assertSame($a, $b);450 }451 /**452 * @dataProvider notSameProvider453 *454 * @throws ExpectationFailedException455 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException456 */457 public function testAssertNotSameSucceeds($a, $b): void458 {459 $this->assertNotSame($a, $b);460 }461 /**462 * @dataProvider sameProvider463 *464 * @throws ExpectationFailedException465 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException466 */467 public function testAssertNotSameFails($a, $b): void468 {469 $this->expectException(AssertionFailedError::class);470 $this->assertNotSame($a, $b);471 }472 public function testAssertXmlFileEqualsXmlFile(): void473 {474 $this->assertXmlFileEqualsXmlFile(475 TEST_FILES_PATH . 'foo.xml',476 TEST_FILES_PATH . 'foo.xml'477 );478 $this->expectException(AssertionFailedError::class);479 $this->assertXmlFileEqualsXmlFile(480 TEST_FILES_PATH . 'foo.xml',481 TEST_FILES_PATH . 'bar.xml'482 );483 }484 public function testAssertXmlFileNotEqualsXmlFile(): void485 {486 $this->assertXmlFileNotEqualsXmlFile(487 TEST_FILES_PATH . 'foo.xml',488 TEST_FILES_PATH . 'bar.xml'489 );490 $this->expectException(AssertionFailedError::class);491 $this->assertXmlFileNotEqualsXmlFile(492 TEST_FILES_PATH . 'foo.xml',493 TEST_FILES_PATH . 'foo.xml'494 );495 }496 public function testAssertXmlStringEqualsXmlFile(): void497 {498 $this->assertXmlStringEqualsXmlFile(499 TEST_FILES_PATH . 'foo.xml',500 \file_get_contents(TEST_FILES_PATH . 'foo.xml')501 );502 $this->expectException(AssertionFailedError::class);503 $this->assertXmlStringEqualsXmlFile(504 TEST_FILES_PATH . 'foo.xml',505 \file_get_contents(TEST_FILES_PATH . 'bar.xml')506 );507 }508 public function testXmlStringNotEqualsXmlFile(): void509 {510 $this->assertXmlStringNotEqualsXmlFile(511 TEST_FILES_PATH . 'foo.xml',512 \file_get_contents(TEST_FILES_PATH . 'bar.xml')513 );514 $this->expectException(AssertionFailedError::class);515 $this->assertXmlStringNotEqualsXmlFile(516 TEST_FILES_PATH . 'foo.xml',517 \file_get_contents(TEST_FILES_PATH . 'foo.xml')518 );519 }520 public function testAssertXmlStringEqualsXmlString(): void521 {522 $this->assertXmlStringEqualsXmlString('<root/>', '<root/>');523 $this->expectException(AssertionFailedError::class);524 $this->assertXmlStringEqualsXmlString('<foo/>', '<bar/>');525 }526 /**527 * @ticket 1860528 */529 public function testAssertXmlStringEqualsXmlString2(): void530 {531 $this->expectException(Exception::class);532 $this->assertXmlStringEqualsXmlString('<a></b>', '<c></d>');533 }534 /**535 * @ticket 1860536 */537 public function testAssertXmlStringEqualsXmlString3(): void538 {539 $expected = <<<XML540<?xml version="1.0"?>541<root>542 <node />543</root>544XML;545 $actual = <<<XML546<?xml version="1.0"?>547<root>548<node />549</root>550XML;551 $this->assertXmlStringEqualsXmlString($expected, $actual);552 }553 public function testAssertXmlStringNotEqualsXmlString(): void554 {555 $this->assertXmlStringNotEqualsXmlString('<foo/>', '<bar/>');556 $this->expectException(AssertionFailedError::class);557 $this->assertXmlStringNotEqualsXmlString('<root/>', '<root/>');558 }559 public function testXMLStructureIsSame(): void560 {561 $expected = new \DOMDocument;562 $expected->load(TEST_FILES_PATH . 'structureExpected.xml');563 $actual = new \DOMDocument;564 $actual->load(TEST_FILES_PATH . 'structureExpected.xml');565 $this->assertEqualXMLStructure(566 $expected->firstChild,567 $actual->firstChild,568 true569 );570 }571 public function testXMLStructureWrongNumberOfAttributes(): void572 {573 $expected = new \DOMDocument;574 $expected->load(TEST_FILES_PATH . 'structureExpected.xml');575 $actual = new \DOMDocument;576 $actual->load(TEST_FILES_PATH . 'structureWrongNumberOfAttributes.xml');577 $this->expectException(ExpectationFailedException::class);578 $this->assertEqualXMLStructure(579 $expected->firstChild,580 $actual->firstChild,581 true582 );583 }584 public function testXMLStructureWrongNumberOfNodes(): void585 {586 $expected = new \DOMDocument;587 $expected->load(TEST_FILES_PATH . 'structureExpected.xml');588 $actual = new \DOMDocument;589 $actual->load(TEST_FILES_PATH . 'structureWrongNumberOfNodes.xml');590 $this->expectException(ExpectationFailedException::class);591 $this->assertEqualXMLStructure(592 $expected->firstChild,593 $actual->firstChild,594 true595 );596 }597 public function testXMLStructureIsSameButDataIsNot(): void598 {599 $expected = new \DOMDocument;600 $expected->load(TEST_FILES_PATH . 'structureExpected.xml');601 $actual = new \DOMDocument;602 $actual->load(TEST_FILES_PATH . 'structureIsSameButDataIsNot.xml');603 $this->assertEqualXMLStructure(604 $expected->firstChild,605 $actual->firstChild,606 true607 );608 }609 public function testXMLStructureAttributesAreSameButValuesAreNot(): void610 {611 $expected = new \DOMDocument;612 $expected->load(TEST_FILES_PATH . 'structureExpected.xml');613 $actual = new \DOMDocument;614 $actual->load(TEST_FILES_PATH . 'structureAttributesAreSameButValuesAreNot.xml');615 $this->assertEqualXMLStructure(616 $expected->firstChild,617 $actual->firstChild,618 true619 );620 }621 public function testXMLStructureIgnoreTextNodes(): void622 {623 $expected = new \DOMDocument;624 $expected->load(TEST_FILES_PATH . 'structureExpected.xml');625 $actual = new \DOMDocument;626 $actual->load(TEST_FILES_PATH . 'structureIgnoreTextNodes.xml');627 $this->assertEqualXMLStructure(628 $expected->firstChild,629 $actual->firstChild,630 true631 );632 }633 public function testAssertStringEqualsNumeric(): void634 {635 $this->assertEquals('0', 0);636 $this->expectException(AssertionFailedError::class);637 $this->assertEquals('0', 1);638 }639 public function testAssertStringEqualsNumeric2(): void640 {641 $this->assertNotEquals('A', 0);642 }643 public function testAssertIsReadable(): void644 {645 $this->assertIsReadable(__FILE__);646 $this->expectException(AssertionFailedError::class);647 $this->assertIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');648 }649 public function testAssertNotIsReadable(): void650 {651 $this->assertNotIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');652 $this->expectException(AssertionFailedError::class);653 $this->assertNotIsReadable(__FILE__);654 }655 public function testAssertIsWritable(): void656 {657 $this->assertIsWritable(__FILE__);658 $this->expectException(AssertionFailedError::class);659 $this->assertIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');660 }661 public function testAssertNotIsWritable(): void662 {663 $this->assertNotIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');664 $this->expectException(AssertionFailedError::class);665 $this->assertNotIsWritable(__FILE__);666 }667 public function testAssertDirectoryExists(): void668 {669 $this->assertDirectoryExists(__DIR__);670 $this->expectException(AssertionFailedError::class);671 $this->assertDirectoryExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');672 }673 public function testAssertDirectoryNotExists(): void674 {675 $this->assertDirectoryNotExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');676 $this->expectException(AssertionFailedError::class);677 $this->assertDirectoryNotExists(__DIR__);678 }679 public function testAssertDirectoryIsReadable(): void680 {681 $this->assertDirectoryIsReadable(__DIR__);682 $this->expectException(AssertionFailedError::class);683 $this->assertDirectoryIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');684 }685 public function testAssertDirectoryIsWritable(): void686 {687 $this->assertDirectoryIsWritable(__DIR__);688 $this->expectException(AssertionFailedError::class);689 $this->assertDirectoryIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');690 }691 public function testAssertFileExists(): void692 {693 $this->assertFileExists(__FILE__);694 $this->expectException(AssertionFailedError::class);695 $this->assertFileExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');696 }697 public function testAssertFileNotExists(): void698 {699 $this->assertFileNotExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');700 $this->expectException(AssertionFailedError::class);701 $this->assertFileNotExists(__FILE__);702 }703 public function testAssertFileIsReadable(): void704 {705 $this->assertFileIsReadable(__FILE__);706 $this->expectException(AssertionFailedError::class);707 $this->assertFileIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');708 }709 public function testAssertFileIsWritable(): void710 {711 $this->assertFileIsWritable(__FILE__);712 $this->expectException(AssertionFailedError::class);713 $this->assertFileIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting');714 }715 public function testAssertObjectHasAttribute(): void716 {717 $o = new \Author('Terry Pratchett');718 $this->assertObjectHasAttribute('name', $o);719 $this->expectException(AssertionFailedError::class);720 $this->assertObjectHasAttribute('foo', $o);721 }722 public function testAssertObjectHasAttributeNumericAttribute(): void723 {724 $object = new \stdClass;725 $object->{'2020'} = 'Tokyo';726 $this->assertObjectHasAttribute('2020', $object);727 $this->expectException(AssertionFailedError::class);728 $this->assertObjectHasAttribute('2018', $object);729 }730 public function testAssertObjectHasAttributeMultiByteAttribute(): void731 {732 $object = new \stdClass;733 $object->{'æ±äº¬'} = 2020;734 $this->assertObjectHasAttribute('æ±äº¬', $object);735 $this->expectException(AssertionFailedError::class);736 $this->assertObjectHasAttribute('é·é', $object);737 }738 public function testAssertObjectNotHasAttribute(): void739 {740 $o = new \Author('Terry Pratchett');741 $this->assertObjectNotHasAttribute('foo', $o);742 $this->expectException(AssertionFailedError::class);743 $this->assertObjectNotHasAttribute('name', $o);744 }745 public function testAssertObjectNotHasAttributeNumericAttribute(): void746 {747 $object = new \stdClass;748 $object->{'2020'} = 'Tokyo';749 $this->assertObjectNotHasAttribute('2018', $object);750 $this->expectException(AssertionFailedError::class);751 $this->assertObjectNotHasAttribute('2020', $object);752 }753 public function testAssertObjectNotHasAttributeMultiByteAttribute(): void754 {755 $object = new \stdClass;756 $object->{'æ±äº¬'} = 2020;757 $this->assertObjectNotHasAttribute('é·é', $object);758 $this->expectException(AssertionFailedError::class);759 $this->assertObjectNotHasAttribute('æ±äº¬', $object);760 }761 public function testAssertFinite(): void762 {763 $this->assertFinite(1);764 $this->expectException(AssertionFailedError::class);765 $this->assertFinite(\INF);766 }767 public function testAssertInfinite(): void768 {769 $this->assertInfinite(\INF);770 $this->expectException(AssertionFailedError::class);771 $this->assertInfinite(1);772 }773 public function testAssertNan(): void774 {775 $this->assertNan(\NAN);776 $this->expectException(AssertionFailedError::class);777 $this->assertNan(1);778 }779 public function testAssertNull(): void780 {781 $this->assertNull(null);782 $this->expectException(AssertionFailedError::class);783 $this->assertNull(new \stdClass);784 }785 public function testAssertNotNull(): void786 {787 $this->assertNotNull(new \stdClass);788 $this->expectException(AssertionFailedError::class);789 $this->assertNotNull(null);790 }791 public function testAssertTrue(): void792 {793 $this->assertTrue(true);794 $this->expectException(AssertionFailedError::class);795 $this->assertTrue(false);796 }797 public function testAssertNotTrue(): void798 {799 $this->assertNotTrue(false);800 $this->assertNotTrue(1);801 $this->assertNotTrue('true');802 $this->expectException(AssertionFailedError::class);803 $this->assertNotTrue(true);804 }805 public function testAssertFalse(): void806 {807 $this->assertFalse(false);808 $this->expectException(AssertionFailedError::class);809 $this->assertFalse(true);810 }811 public function testAssertNotFalse(): void812 {813 $this->assertNotFalse(true);814 $this->assertNotFalse(0);815 $this->assertNotFalse('');816 $this->expectException(AssertionFailedError::class);817 $this->assertNotFalse(false);818 }819 public function testAssertRegExp(): void820 {821 $this->assertRegExp('/foo/', 'foobar');822 $this->expectException(AssertionFailedError::class);823 $this->assertRegExp('/foo/', 'bar');824 }825 public function testAssertNotRegExp(): void826 {827 $this->assertNotRegExp('/foo/', 'bar');828 $this->expectException(AssertionFailedError::class);829 $this->assertNotRegExp('/foo/', 'foobar');830 }831 public function testAssertSame(): void832 {833 $o = new \stdClass;834 $this->assertSame($o, $o);835 $this->expectException(AssertionFailedError::class);836 $this->assertSame(new \stdClass, new \stdClass);837 }838 public function testAssertSame2(): void839 {840 $this->assertSame(true, true);841 $this->assertSame(false, false);842 $this->expectException(AssertionFailedError::class);843 $this->assertSame(true, false);844 }845 public function testAssertNotSame(): void846 {847 $this->assertNotSame(848 new \stdClass,849 null850 );851 $this->assertNotSame(852 null,853 new \stdClass854 );855 $this->assertNotSame(856 new \stdClass,857 new \stdClass858 );859 $o = new \stdClass;860 $this->expectException(AssertionFailedError::class);861 $this->assertNotSame($o, $o);862 }863 public function testAssertNotSame2(): void864 {865 $this->assertNotSame(true, false);866 $this->assertNotSame(false, true);867 $this->expectException(AssertionFailedError::class);868 $this->assertNotSame(true, true);869 }870 public function testAssertNotSameFailsNull(): void871 {872 $this->expectException(AssertionFailedError::class);873 $this->assertNotSame(null, null);874 }875 public function testGreaterThan(): void876 {877 $this->assertGreaterThan(1, 2);878 $this->expectException(AssertionFailedError::class);879 $this->assertGreaterThan(2, 1);880 }881 public function testAttributeGreaterThan(): void882 {883 $this->assertAttributeGreaterThan(884 1,885 'bar',886 new \ClassWithNonPublicAttributes887 );888 $this->expectException(AssertionFailedError::class);889 $this->assertAttributeGreaterThan(890 1,891 'foo',892 new \ClassWithNonPublicAttributes893 );894 }895 public function testGreaterThanOrEqual(): void896 {897 $this->assertGreaterThanOrEqual(1, 2);898 $this->expectException(AssertionFailedError::class);899 $this->assertGreaterThanOrEqual(2, 1);900 }901 public function testAttributeGreaterThanOrEqual(): void902 {903 $this->assertAttributeGreaterThanOrEqual(904 1,905 'bar',906 new \ClassWithNonPublicAttributes907 );908 $this->expectException(AssertionFailedError::class);909 $this->assertAttributeGreaterThanOrEqual(910 2,911 'foo',912 new \ClassWithNonPublicAttributes913 );914 }915 public function testLessThan(): void916 {917 $this->assertLessThan(2, 1);918 try {919 $this->assertLessThan(1, 2);920 } catch (AssertionFailedError $e) {921 return;922 }923 $this->fail();924 }925 public function testAttributeLessThan(): void926 {927 $this->assertAttributeLessThan(928 2,929 'foo',930 new \ClassWithNonPublicAttributes931 );932 $this->expectException(AssertionFailedError::class);933 $this->assertAttributeLessThan(934 1,935 'bar',936 new \ClassWithNonPublicAttributes937 );938 }939 public function testLessThanOrEqual(): void940 {941 $this->assertLessThanOrEqual(2, 1);942 $this->expectException(AssertionFailedError::class);943 $this->assertLessThanOrEqual(1, 2);944 }945 public function testAttributeLessThanOrEqual(): void946 {947 $this->assertAttributeLessThanOrEqual(948 2,949 'foo',950 new \ClassWithNonPublicAttributes951 );952 $this->expectException(AssertionFailedError::class);953 $this->assertAttributeLessThanOrEqual(954 1,955 'bar',956 new \ClassWithNonPublicAttributes957 );958 }959 public function testReadAttribute(): void960 {961 $obj = new \ClassWithNonPublicAttributes;962 $this->assertEquals('foo', $this->readAttribute($obj, 'publicAttribute'));963 $this->assertEquals('bar', $this->readAttribute($obj, 'protectedAttribute'));964 $this->assertEquals('baz', $this->readAttribute($obj, 'privateAttribute'));965 $this->assertEquals('bar', $this->readAttribute($obj, 'protectedParentAttribute'));966 //$this->assertEquals('bar', $this->readAttribute($obj, 'privateParentAttribute'));967 }968 public function testReadAttribute2(): void969 {970 $this->assertEquals('foo', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'publicStaticAttribute'));971 $this->assertEquals('bar', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'protectedStaticAttribute'));972 $this->assertEquals('baz', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'privateStaticAttribute'));973 $this->assertEquals('foo', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'protectedStaticParentAttribute'));974 $this->assertEquals('foo', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'privateStaticParentAttribute'));975 }976 public function testReadAttribute4(): void977 {978 $this->expectException(Exception::class);979 $this->readAttribute('NotExistingClass', 'foo');980 }981 public function testReadAttribute5(): void982 {983 $this->expectException(Exception::class);984 $this->readAttribute(null, 'foo');985 }986 public function testReadAttributeIfAttributeNameIsNotValid(): void987 {988 $this->expectException(Exception::class);989 $this->readAttribute(\stdClass::class, '2');990 }991 public function testGetStaticAttributeRaisesExceptionForInvalidFirstArgument2(): void992 {993 $this->expectException(Exception::class);994 $this->getStaticAttribute('NotExistingClass', 'foo');995 }996 public function testGetStaticAttributeRaisesExceptionForInvalidSecondArgument2(): void997 {998 $this->expectException(Exception::class);999 $this->getStaticAttribute(\stdClass::class, '0');1000 }1001 public function testGetStaticAttributeRaisesExceptionForInvalidSecondArgument3(): void1002 {1003 $this->expectException(Exception::class);1004 $this->getStaticAttribute(\stdClass::class, 'foo');1005 }1006 public function testGetObjectAttributeRaisesExceptionForInvalidFirstArgument(): void1007 {1008 $this->expectException(Exception::class);1009 $this->getObjectAttribute(null, 'foo');1010 }1011 public function testGetObjectAttributeRaisesExceptionForInvalidSecondArgument2(): void1012 {1013 $this->expectException(Exception::class);1014 $this->getObjectAttribute(new \stdClass, '0');1015 }1016 public function testGetObjectAttributeRaisesExceptionForInvalidSecondArgument3(): void1017 {1018 $this->expectException(Exception::class);1019 $this->getObjectAttribute(new \stdClass, 'foo');1020 }1021 public function testGetObjectAttributeWorksForInheritedAttributes(): void1022 {1023 $this->assertEquals(1024 'bar',1025 $this->getObjectAttribute(new \ClassWithNonPublicAttributes, 'privateParentAttribute')1026 );1027 }1028 public function testAssertPublicAttributeContains(): void1029 {1030 $obj = new \ClassWithNonPublicAttributes;1031 $this->assertAttributeContains('foo', 'publicArray', $obj);1032 $this->expectException(AssertionFailedError::class);1033 $this->assertAttributeContains('bar', 'publicArray', $obj);1034 }1035 public function testAssertPublicAttributeContainsOnly(): void1036 {1037 $obj = new \ClassWithNonPublicAttributes;1038 $this->assertAttributeContainsOnly('string', 'publicArray', $obj);1039 $this->expectException(AssertionFailedError::class);1040 $this->assertAttributeContainsOnly('integer', 'publicArray', $obj);1041 }1042 public function testAssertPublicAttributeNotContains(): void1043 {1044 $obj = new \ClassWithNonPublicAttributes;1045 $this->assertAttributeNotContains('bar', 'publicArray', $obj);1046 $this->expectException(AssertionFailedError::class);1047 $this->assertAttributeNotContains('foo', 'publicArray', $obj);1048 }1049 public function testAssertPublicAttributeNotContainsOnly(): void1050 {1051 $obj = new \ClassWithNonPublicAttributes;1052 $this->assertAttributeNotContainsOnly('integer', 'publicArray', $obj);1053 $this->expectException(AssertionFailedError::class);1054 $this->assertAttributeNotContainsOnly('string', 'publicArray', $obj);1055 }1056 public function testAssertProtectedAttributeContains(): void1057 {1058 $obj = new \ClassWithNonPublicAttributes;1059 $this->assertAttributeContains('bar', 'protectedArray', $obj);1060 $this->expectException(AssertionFailedError::class);1061 $this->assertAttributeContains('foo', 'protectedArray', $obj);1062 }1063 public function testAssertProtectedAttributeNotContains(): void1064 {1065 $obj = new \ClassWithNonPublicAttributes;1066 $this->assertAttributeNotContains('foo', 'protectedArray', $obj);1067 $this->expectException(AssertionFailedError::class);1068 $this->assertAttributeNotContains('bar', 'protectedArray', $obj);1069 }1070 public function testAssertPrivateAttributeContains(): void1071 {1072 $obj = new \ClassWithNonPublicAttributes;1073 $this->assertAttributeContains('baz', 'privateArray', $obj);1074 $this->expectException(AssertionFailedError::class);1075 $this->assertAttributeContains('foo', 'privateArray', $obj);1076 }1077 public function testAssertPrivateAttributeNotContains(): void1078 {1079 $obj = new \ClassWithNonPublicAttributes;1080 $this->assertAttributeNotContains('foo', 'privateArray', $obj);1081 $this->expectException(AssertionFailedError::class);1082 $this->assertAttributeNotContains('baz', 'privateArray', $obj);1083 }1084 public function testAssertAttributeContainsNonObject(): void1085 {1086 $obj = new \ClassWithNonPublicAttributes;1087 $this->assertAttributeContains(true, 'privateArray', $obj);1088 $this->expectException(AssertionFailedError::class);1089 $this->assertAttributeContains(true, 'privateArray', $obj, '', false, true, true);1090 }1091 public function testAssertAttributeNotContainsNonObject(): void1092 {1093 $obj = new \ClassWithNonPublicAttributes;1094 $this->assertAttributeNotContains(true, 'privateArray', $obj, '', false, true, true);1095 $this->expectException(AssertionFailedError::class);1096 $this->assertAttributeNotContains(true, 'privateArray', $obj);1097 }1098 public function testAssertPublicAttributeEquals(): void1099 {1100 $obj = new \ClassWithNonPublicAttributes;1101 $this->assertAttributeEquals('foo', 'publicAttribute', $obj);1102 $this->expectException(AssertionFailedError::class);1103 $this->assertAttributeEquals('bar', 'publicAttribute', $obj);1104 }1105 public function testAssertPublicAttributeNotEquals(): void1106 {1107 $obj = new \ClassWithNonPublicAttributes;1108 $this->assertAttributeNotEquals('bar', 'publicAttribute', $obj);1109 $this->expectException(AssertionFailedError::class);1110 $this->assertAttributeNotEquals('foo', 'publicAttribute', $obj);1111 }1112 public function testAssertPublicAttributeSame(): void1113 {1114 $obj = new \ClassWithNonPublicAttributes;1115 $this->assertAttributeSame('foo', 'publicAttribute', $obj);1116 $this->expectException(AssertionFailedError::class);1117 $this->assertAttributeSame('bar', 'publicAttribute', $obj);1118 }1119 public function testAssertPublicAttributeNotSame(): void1120 {1121 $obj = new \ClassWithNonPublicAttributes;1122 $this->assertAttributeNotSame('bar', 'publicAttribute', $obj);1123 $this->expectException(AssertionFailedError::class);1124 $this->assertAttributeNotSame('foo', 'publicAttribute', $obj);1125 }1126 public function testAssertProtectedAttributeEquals(): void1127 {1128 $obj = new \ClassWithNonPublicAttributes;1129 $this->assertAttributeEquals('bar', 'protectedAttribute', $obj);1130 $this->expectException(AssertionFailedError::class);1131 $this->assertAttributeEquals('foo', 'protectedAttribute', $obj);1132 }1133 public function testAssertProtectedAttributeNotEquals(): void1134 {1135 $obj = new \ClassWithNonPublicAttributes;1136 $this->assertAttributeNotEquals('foo', 'protectedAttribute', $obj);1137 $this->expectException(AssertionFailedError::class);1138 $this->assertAttributeNotEquals('bar', 'protectedAttribute', $obj);1139 }1140 public function testAssertPrivateAttributeEquals(): void1141 {1142 $obj = new \ClassWithNonPublicAttributes;1143 $this->assertAttributeEquals('baz', 'privateAttribute', $obj);1144 $this->expectException(AssertionFailedError::class);1145 $this->assertAttributeEquals('foo', 'privateAttribute', $obj);1146 }1147 public function testAssertPrivateAttributeNotEquals(): void1148 {1149 $obj = new \ClassWithNonPublicAttributes;1150 $this->assertAttributeNotEquals('foo', 'privateAttribute', $obj);1151 $this->expectException(AssertionFailedError::class);1152 $this->assertAttributeNotEquals('baz', 'privateAttribute', $obj);1153 }1154 public function testAssertPublicStaticAttributeEquals(): void1155 {1156 $this->assertAttributeEquals('foo', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class);1157 $this->expectException(AssertionFailedError::class);1158 $this->assertAttributeEquals('bar', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class);1159 }1160 public function testAssertPublicStaticAttributeNotEquals(): void1161 {1162 $this->assertAttributeNotEquals('bar', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class);1163 $this->expectException(AssertionFailedError::class);1164 $this->assertAttributeNotEquals('foo', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class);1165 }1166 public function testAssertProtectedStaticAttributeEquals(): void1167 {1168 $this->assertAttributeEquals('bar', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class);1169 $this->expectException(AssertionFailedError::class);1170 $this->assertAttributeEquals('foo', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class);1171 }1172 public function testAssertProtectedStaticAttributeNotEquals(): void1173 {1174 $this->assertAttributeNotEquals('foo', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class);1175 $this->expectException(AssertionFailedError::class);1176 $this->assertAttributeNotEquals('bar', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class);1177 }1178 public function testAssertPrivateStaticAttributeEquals(): void1179 {1180 $this->assertAttributeEquals('baz', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class);1181 $this->expectException(AssertionFailedError::class);1182 $this->assertAttributeEquals('foo', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class);1183 }1184 public function testAssertPrivateStaticAttributeNotEquals(): void1185 {1186 $this->assertAttributeNotEquals('foo', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class);1187 $this->expectException(AssertionFailedError::class);1188 $this->assertAttributeNotEquals('baz', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class);1189 }1190 public function testAssertClassHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void1191 {1192 $this->expectException(Exception::class);1193 $this->assertClassHasAttribute('1', \ClassWithNonPublicAttributes::class);1194 }1195 public function testAssertClassHasAttributeThrowsExceptionIfClassDoesNotExist(): void1196 {1197 $this->expectException(Exception::class);1198 $this->assertClassHasAttribute('attribute', 'ClassThatDoesNotExist');1199 }1200 public function testAssertClassNotHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void1201 {1202 $this->expectException(Exception::class);1203 $this->assertClassNotHasAttribute('1', \ClassWithNonPublicAttributes::class);1204 }1205 public function testAssertClassNotHasAttributeThrowsExceptionIfClassDoesNotExist(): void1206 {1207 $this->expectException(Exception::class);1208 $this->assertClassNotHasAttribute('attribute', 'ClassThatDoesNotExist');1209 }1210 public function testAssertClassHasStaticAttributeThrowsExceptionIfAttributeNameIsNotValid(): void1211 {1212 $this->expectException(Exception::class);1213 $this->assertClassHasStaticAttribute('1', \ClassWithNonPublicAttributes::class);1214 }1215 public function testAssertClassHasStaticAttributeThrowsExceptionIfClassDoesNotExist(): void1216 {1217 $this->expectException(Exception::class);1218 $this->assertClassHasStaticAttribute('attribute', 'ClassThatDoesNotExist');1219 }1220 public function testAssertClassNotHasStaticAttributeThrowsExceptionIfAttributeNameIsNotValid(): void1221 {1222 $this->expectException(Exception::class);1223 $this->assertClassNotHasStaticAttribute('1', \ClassWithNonPublicAttributes::class);1224 }1225 public function testAssertClassNotHasStaticAttributeThrowsExceptionIfClassDoesNotExist(): void1226 {1227 $this->expectException(Exception::class);1228 $this->assertClassNotHasStaticAttribute('attribute', 'ClassThatDoesNotExist');1229 }1230 public function testAssertObjectHasAttributeThrowsException2(): void1231 {1232 $this->expectException(Exception::class);1233 $this->assertObjectHasAttribute('foo', null);1234 }1235 public function testAssertObjectHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void1236 {1237 $this->expectException(Exception::class);1238 $this->assertObjectHasAttribute('1', \ClassWithNonPublicAttributes::class);1239 }1240 public function testAssertObjectNotHasAttributeThrowsException2(): void1241 {1242 $this->expectException(Exception::class);1243 $this->assertObjectNotHasAttribute('foo', null);1244 }1245 public function testAssertObjectNotHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void1246 {1247 $this->expectException(Exception::class);1248 $this->assertObjectNotHasAttribute('1', \ClassWithNonPublicAttributes::class);1249 }1250 public function testClassHasPublicAttribute(): void1251 {1252 $this->assertClassHasAttribute('publicAttribute', \ClassWithNonPublicAttributes::class);1253 $this->expectException(AssertionFailedError::class);1254 $this->assertClassHasAttribute('attribute', \ClassWithNonPublicAttributes::class);1255 }1256 public function testClassNotHasPublicAttribute(): void1257 {1258 $this->assertClassNotHasAttribute('attribute', \ClassWithNonPublicAttributes::class);1259 $this->expectException(AssertionFailedError::class);1260 $this->assertClassNotHasAttribute('publicAttribute', \ClassWithNonPublicAttributes::class);1261 }1262 public function testClassHasPublicStaticAttribute(): void1263 {1264 $this->assertClassHasStaticAttribute('publicStaticAttribute', \ClassWithNonPublicAttributes::class);1265 $this->expectException(AssertionFailedError::class);1266 $this->assertClassHasStaticAttribute('attribute', \ClassWithNonPublicAttributes::class);1267 }1268 public function testClassNotHasPublicStaticAttribute(): void1269 {1270 $this->assertClassNotHasStaticAttribute('attribute', \ClassWithNonPublicAttributes::class);1271 $this->expectException(AssertionFailedError::class);1272 $this->assertClassNotHasStaticAttribute('publicStaticAttribute', \ClassWithNonPublicAttributes::class);1273 }1274 public function testObjectHasPublicAttribute(): void1275 {1276 $obj = new \ClassWithNonPublicAttributes;1277 $this->assertObjectHasAttribute('publicAttribute', $obj);1278 $this->expectException(AssertionFailedError::class);1279 $this->assertObjectHasAttribute('attribute', $obj);1280 }1281 public function testObjectNotHasPublicAttribute(): void1282 {1283 $obj = new \ClassWithNonPublicAttributes;1284 $this->assertObjectNotHasAttribute('attribute', $obj);1285 $this->expectException(AssertionFailedError::class);1286 $this->assertObjectNotHasAttribute('publicAttribute', $obj);1287 }1288 public function testObjectHasOnTheFlyAttribute(): void1289 {1290 $obj = new \stdClass;1291 $obj->foo = 'bar';1292 $this->assertObjectHasAttribute('foo', $obj);1293 $this->expectException(AssertionFailedError::class);1294 $this->assertObjectHasAttribute('bar', $obj);1295 }1296 public function testObjectNotHasOnTheFlyAttribute(): void1297 {1298 $obj = new \stdClass;1299 $obj->foo = 'bar';1300 $this->assertObjectNotHasAttribute('bar', $obj);1301 $this->expectException(AssertionFailedError::class);1302 $this->assertObjectNotHasAttribute('foo', $obj);1303 }1304 public function testObjectHasProtectedAttribute(): void1305 {1306 $obj = new \ClassWithNonPublicAttributes;1307 $this->assertObjectHasAttribute('protectedAttribute', $obj);1308 $this->expectException(AssertionFailedError::class);1309 $this->assertObjectHasAttribute('attribute', $obj);1310 }1311 public function testObjectNotHasProtectedAttribute(): void1312 {1313 $obj = new \ClassWithNonPublicAttributes;1314 $this->assertObjectNotHasAttribute('attribute', $obj);1315 $this->expectException(AssertionFailedError::class);1316 $this->assertObjectNotHasAttribute('protectedAttribute', $obj);1317 }1318 public function testObjectHasPrivateAttribute(): void1319 {1320 $obj = new \ClassWithNonPublicAttributes;1321 $this->assertObjectHasAttribute('privateAttribute', $obj);1322 $this->expectException(AssertionFailedError::class);1323 $this->assertObjectHasAttribute('attribute', $obj);1324 }1325 public function testObjectNotHasPrivateAttribute(): void1326 {1327 $obj = new \ClassWithNonPublicAttributes;1328 $this->assertObjectNotHasAttribute('attribute', $obj);1329 $this->expectException(AssertionFailedError::class);1330 $this->assertObjectNotHasAttribute('privateAttribute', $obj);1331 }1332 public function testAssertThatAttributeEquals(): void1333 {1334 $this->assertThat(1335 new \ClassWithNonPublicAttributes,1336 $this->attribute(1337 $this->equalTo('foo'),1338 'publicAttribute'1339 )1340 );1341 }1342 public function testAssertThatAttributeEquals2(): void1343 {1344 $this->expectException(AssertionFailedError::class);1345 $this->assertThat(1346 new \ClassWithNonPublicAttributes,1347 $this->attribute(1348 $this->equalTo('bar'),1349 'publicAttribute'1350 )1351 );1352 }1353 public function testAssertThatAttributeEqualTo(): void1354 {1355 $this->assertThat(1356 new \ClassWithNonPublicAttributes,1357 $this->attributeEqualTo('publicAttribute', 'foo')1358 );1359 }1360 /**1361 * @doesNotPerformAssertions1362 */1363 public function testAssertThatAnything(): void1364 {1365 $this->assertThat('anything', $this->anything());1366 }1367 public function testAssertThatIsTrue(): void1368 {1369 $this->assertThat(true, $this->isTrue());1370 }1371 public function testAssertThatIsFalse(): void1372 {1373 $this->assertThat(false, $this->isFalse());1374 }1375 public function testAssertThatIsJson(): void1376 {1377 $this->assertThat('{}', $this->isJson());1378 }1379 /**1380 * @doesNotPerformAssertions1381 */1382 public function testAssertThatAnythingAndAnything(): void1383 {1384 $this->assertThat(1385 'anything',1386 $this->logicalAnd(1387 $this->anything(),1388 $this->anything()1389 )1390 );1391 }1392 /**1393 * @doesNotPerformAssertions1394 */1395 public function testAssertThatAnythingOrAnything(): void1396 {1397 $this->assertThat(1398 'anything',1399 $this->logicalOr(1400 $this->anything(),1401 $this->anything()1402 )1403 );1404 }1405 /**1406 * @doesNotPerformAssertions1407 */1408 public function testAssertThatAnythingXorNotAnything(): void1409 {1410 $this->assertThat(1411 'anything',1412 $this->logicalXor(1413 $this->anything(),1414 $this->logicalNot($this->anything())1415 )1416 );1417 }1418 public function testAssertThatContains(): void1419 {1420 $this->assertThat(['foo'], $this->contains('foo'));1421 }1422 public function testAssertThatStringContains(): void1423 {1424 $this->assertThat('barfoobar', $this->stringContains('foo'));1425 }1426 public function testAssertThatContainsOnly(): void1427 {1428 $this->assertThat(['foo'], $this->containsOnly('string'));1429 }1430 public function testAssertThatContainsOnlyInstancesOf(): void1431 {1432 $this->assertThat([new \Book], $this->containsOnlyInstancesOf(\Book::class));1433 }1434 public function testAssertThatArrayHasKey(): void1435 {1436 $this->assertThat(['foo' => 'bar'], $this->arrayHasKey('foo'));1437 }1438 public function testAssertThatClassHasAttribute(): void1439 {1440 $this->assertThat(1441 new \ClassWithNonPublicAttributes,1442 $this->classHasAttribute('publicAttribute')1443 );1444 }1445 public function testAssertThatClassHasStaticAttribute(): void1446 {1447 $this->assertThat(1448 new \ClassWithNonPublicAttributes,1449 $this->classHasStaticAttribute('publicStaticAttribute')1450 );1451 }1452 public function testAssertThatObjectHasAttribute(): void1453 {1454 $this->assertThat(1455 new \ClassWithNonPublicAttributes,1456 $this->objectHasAttribute('publicAttribute')1457 );1458 }1459 public function testAssertThatEqualTo(): void1460 {1461 $this->assertThat('foo', $this->equalTo('foo'));1462 }1463 public function testAssertThatIdenticalTo(): void1464 {1465 $value = new \stdClass;1466 $constraint = $this->identicalTo($value);1467 $this->assertThat($value, $constraint);1468 }1469 public function testAssertThatIsInstanceOf(): void1470 {1471 $this->assertThat(new \stdClass, $this->isInstanceOf('StdClass'));1472 }1473 public function testAssertThatIsType(): void1474 {1475 $this->assertThat('string', $this->isType('string'));1476 }1477 public function testAssertThatIsEmpty(): void1478 {1479 $this->assertThat([], $this->isEmpty());1480 }1481 public function testAssertThatFileExists(): void1482 {1483 $this->assertThat(__FILE__, $this->fileExists());1484 }1485 public function testAssertThatGreaterThan(): void1486 {1487 $this->assertThat(2, $this->greaterThan(1));1488 }1489 public function testAssertThatGreaterThanOrEqual(): void1490 {1491 $this->assertThat(2, $this->greaterThanOrEqual(1));1492 }1493 public function testAssertThatLessThan(): void1494 {1495 $this->assertThat(1, $this->lessThan(2));1496 }1497 public function testAssertThatLessThanOrEqual(): void1498 {1499 $this->assertThat(1, $this->lessThanOrEqual(2));1500 }1501 public function testAssertThatMatchesRegularExpression(): void1502 {1503 $this->assertThat('foobar', $this->matchesRegularExpression('/foo/'));1504 }1505 public function testAssertThatCallback(): void1506 {1507 $this->assertThat(1508 null,1509 $this->callback(function ($other) {1510 return true;1511 })1512 );1513 }1514 public function testAssertThatCountOf(): void1515 {1516 $this->assertThat([1], $this->countOf(1));1517 }1518 public function testAssertFileEquals(): void1519 {1520 $this->assertFileEquals(1521 TEST_FILES_PATH . 'foo.xml',1522 TEST_FILES_PATH . 'foo.xml'1523 );1524 $this->expectException(AssertionFailedError::class);1525 $this->assertFileEquals(1526 TEST_FILES_PATH . 'foo.xml',1527 TEST_FILES_PATH . 'bar.xml'1528 );1529 }1530 public function testAssertFileNotEquals(): void1531 {1532 $this->assertFileNotEquals(1533 TEST_FILES_PATH . 'foo.xml',1534 TEST_FILES_PATH . 'bar.xml'1535 );1536 $this->expectException(AssertionFailedError::class);1537 $this->assertFileNotEquals(1538 TEST_FILES_PATH . 'foo.xml',1539 TEST_FILES_PATH . 'foo.xml'1540 );1541 }1542 public function testAssertStringEqualsFile(): void1543 {1544 $this->assertStringEqualsFile(1545 TEST_FILES_PATH . 'foo.xml',1546 \file_get_contents(TEST_FILES_PATH . 'foo.xml')1547 );1548 $this->expectException(AssertionFailedError::class);1549 $this->assertStringEqualsFile(1550 TEST_FILES_PATH . 'foo.xml',1551 \file_get_contents(TEST_FILES_PATH . 'bar.xml')1552 );1553 }1554 public function testAssertStringNotEqualsFile(): void1555 {1556 $this->assertStringNotEqualsFile(1557 TEST_FILES_PATH . 'foo.xml',1558 \file_get_contents(TEST_FILES_PATH . 'bar.xml')1559 );1560 $this->expectException(AssertionFailedError::class);1561 $this->assertStringNotEqualsFile(1562 TEST_FILES_PATH . 'foo.xml',1563 \file_get_contents(TEST_FILES_PATH . 'foo.xml')1564 );1565 }1566 public function testAssertStringStartsNotWithThrowsException2(): void1567 {1568 $this->expectException(Exception::class);1569 $this->assertStringStartsNotWith('', null);1570 }1571 public function testAssertStringStartsWith(): void1572 {1573 $this->assertStringStartsWith('prefix', 'prefixfoo');1574 $this->expectException(AssertionFailedError::class);1575 $this->assertStringStartsWith('prefix', 'foo');1576 }1577 public function testAssertStringStartsNotWith(): void1578 {1579 $this->assertStringStartsNotWith('prefix', 'foo');1580 $this->expectException(AssertionFailedError::class);1581 $this->assertStringStartsNotWith('prefix', 'prefixfoo');1582 }1583 public function testAssertStringEndsWith(): void1584 {1585 $this->assertStringEndsWith('suffix', 'foosuffix');1586 $this->expectException(AssertionFailedError::class);1587 $this->assertStringEndsWith('suffix', 'foo');1588 }1589 public function testAssertStringEndsNotWith(): void1590 {1591 $this->assertStringEndsNotWith('suffix', 'foo');1592 $this->expectException(AssertionFailedError::class);1593 $this->assertStringEndsNotWith('suffix', 'foosuffix');1594 }1595 public function testAssertStringMatchesFormat(): void1596 {1597 $this->assertStringMatchesFormat('*%s*', '***');1598 }1599 public function testAssertStringMatchesFormatFailure(): void1600 {1601 $this->expectException(AssertionFailedError::class);1602 $this->assertStringMatchesFormat('*%s*', '**');1603 }1604 public function testAssertStringNotMatchesFormat(): void1605 {1606 $this->assertStringNotMatchesFormat('*%s*', '**');1607 $this->expectException(AssertionFailedError::class);1608 $this->assertStringMatchesFormat('*%s*', '**');1609 }1610 public function testAssertEmpty(): void1611 {1612 $this->assertEmpty([]);1613 $this->expectException(AssertionFailedError::class);1614 $this->assertEmpty(['foo']);1615 }1616 public function testAssertNotEmpty(): void1617 {1618 $this->assertNotEmpty(['foo']);1619 $this->expectException(AssertionFailedError::class);1620 $this->assertNotEmpty([]);1621 }1622 public function testAssertAttributeEmpty(): void1623 {1624 $o = new \stdClass;1625 $o->a = [];1626 $this->assertAttributeEmpty('a', $o);1627 $o->a = ['b'];1628 $this->expectException(AssertionFailedError::class);1629 $this->assertAttributeEmpty('a', $o);1630 }1631 public function testAssertAttributeNotEmpty(): void1632 {1633 $o = new \stdClass;1634 $o->a = ['b'];1635 $this->assertAttributeNotEmpty('a', $o);1636 $o->a = [];1637 $this->expectException(AssertionFailedError::class);1638 $this->assertAttributeNotEmpty('a', $o);1639 }1640 public function testMarkTestIncomplete(): void1641 {1642 try {1643 $this->markTestIncomplete('incomplete');1644 } catch (IncompleteTestError $e) {1645 $this->assertEquals('incomplete', $e->getMessage());1646 return;1647 }1648 $this->fail();1649 }1650 public function testMarkTestSkipped(): void1651 {1652 try {1653 $this->markTestSkipped('skipped');1654 } catch (SkippedTestError $e) {1655 $this->assertEquals('skipped', $e->getMessage());1656 return;1657 }1658 $this->fail();1659 }1660 public function testAssertCount(): void1661 {1662 $this->assertCount(2, [1, 2]);1663 $this->expectException(AssertionFailedError::class);1664 $this->assertCount(2, [1, 2, 3]);1665 }1666 public function testAssertCountTraversable(): void1667 {1668 $this->assertCount(2, new \ArrayIterator([1, 2]));1669 $this->expectException(AssertionFailedError::class);1670 $this->assertCount(2, new \ArrayIterator([1, 2, 3]));1671 }1672 public function testAssertCountThrowsExceptionIfElementIsNotCountable(): void1673 {1674 try {1675 $this->assertCount(2, '');1676 } catch (Exception $e) {1677 $this->assertEquals('Argument #2 (No Value) of PHPUnit\Framework\Assert::assertCount() must be a countable or iterable', $e->getMessage());1678 return;1679 }1680 $this->fail();1681 }1682 public function testAssertAttributeCount(): void1683 {1684 $o = new \stdClass;1685 $o->a = [];1686 $this->assertAttributeCount(0, 'a', $o);1687 }1688 public function testAssertNotCount(): void1689 {1690 $this->assertNotCount(2, [1, 2, 3]);1691 $this->expectException(AssertionFailedError::class);1692 $this->assertNotCount(2, [1, 2]);1693 }1694 public function testAssertNotCountThrowsExceptionIfElementIsNotCountable(): void1695 {1696 $this->expectException(Exception::class);1697 $this->assertNotCount(2, '');1698 }1699 public function testAssertAttributeNotCount(): void1700 {1701 $o = new \stdClass;1702 $o->a = [];1703 $this->assertAttributeNotCount(1, 'a', $o);1704 }1705 public function testAssertSameSize(): void1706 {1707 $this->assertSameSize([1, 2], [3, 4]);1708 $this->expectException(AssertionFailedError::class);1709 $this->assertSameSize([1, 2], [1, 2, 3]);1710 }1711 public function testAssertSameSizeThrowsExceptionIfExpectedIsNotCountable(): void1712 {1713 try {1714 $this->assertSameSize('a', []);1715 } catch (Exception $e) {1716 $this->assertEquals('Argument #1 (No Value) of PHPUnit\Framework\Assert::assertSameSize() must be a countable or iterable', $e->getMessage());1717 return;1718 }1719 $this->fail();1720 }1721 public function testAssertSameSizeThrowsExceptionIfActualIsNotCountable(): void1722 {1723 try {1724 $this->assertSameSize([], '');1725 } catch (Exception $e) {1726 $this->assertEquals('Argument #2 (No Value) of PHPUnit\Framework\Assert::assertSameSize() must be a countable or iterable', $e->getMessage());1727 return;1728 }1729 $this->fail();1730 }1731 public function testAssertNotSameSize(): void1732 {1733 $this->assertNotSameSize([1, 2], [1, 2, 3]);1734 $this->expectException(AssertionFailedError::class);1735 $this->assertNotSameSize([1, 2], [3, 4]);1736 }1737 public function testAssertNotSameSizeThrowsExceptionIfExpectedIsNotCountable(): void1738 {1739 $this->expectException(Exception::class);1740 $this->assertNotSameSize('a', []);1741 }1742 public function testAssertNotSameSizeThrowsExceptionIfActualIsNotCountable(): void1743 {1744 $this->expectException(Exception::class);1745 $this->assertNotSameSize([], '');1746 }1747 public function testAssertJson(): void1748 {1749 $this->assertJson('{}');1750 }1751 public function testAssertJsonStringEqualsJsonString(): void1752 {1753 $expected = '{"Mascott" : "Tux"}';1754 $actual = '{"Mascott" : "Tux"}';1755 $message = 'Given Json strings do not match';1756 $this->assertJsonStringEqualsJsonString($expected, $actual, $message);1757 }1758 /**1759 * @dataProvider validInvalidJsonDataprovider1760 *1761 * @throws ExpectationFailedException1762 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException1763 */1764 public function testAssertJsonStringEqualsJsonStringErrorRaised($expected, $actual): void1765 {1766 $this->expectException(AssertionFailedError::class);1767 $this->assertJsonStringEqualsJsonString($expected, $actual);1768 }1769 public function testAssertJsonStringNotEqualsJsonString(): void1770 {1771 $expected = '{"Mascott" : "Beastie"}';1772 $actual = '{"Mascott" : "Tux"}';1773 $message = 'Given Json strings do match';1774 $this->assertJsonStringNotEqualsJsonString($expected, $actual, $message);1775 }1776 /**1777 * @dataProvider validInvalidJsonDataprovider1778 *1779 * @throws ExpectationFailedException1780 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException1781 */1782 public function testAssertJsonStringNotEqualsJsonStringErrorRaised($expected, $actual): void1783 {1784 $this->expectException(AssertionFailedError::class);1785 $this->assertJsonStringNotEqualsJsonString($expected, $actual);1786 }1787 public function testAssertJsonStringEqualsJsonFile(): void1788 {1789 $file = TEST_FILES_PATH . 'JsonData/simpleObject.json';1790 $actual = \json_encode(['Mascott' => 'Tux']);1791 $message = '';1792 $this->assertJsonStringEqualsJsonFile($file, $actual, $message);1793 }1794 public function testAssertJsonStringEqualsJsonFileExpectingExpectationFailedException(): void1795 {1796 $file = TEST_FILES_PATH . 'JsonData/simpleObject.json';1797 $actual = \json_encode(['Mascott' => 'Beastie']);1798 $message = '';1799 try {1800 $this->assertJsonStringEqualsJsonFile($file, $actual, $message);1801 } catch (ExpectationFailedException $e) {1802 $this->assertEquals(1803 'Failed asserting that \'{"Mascott":"Beastie"}\' matches JSON string "{"Mascott":"Tux"}".',1804 $e->getMessage()1805 );1806 return;1807 }1808 $this->fail('Expected Exception not thrown.');1809 }1810 public function testAssertJsonStringNotEqualsJsonFile(): void1811 {1812 $file = TEST_FILES_PATH . 'JsonData/simpleObject.json';1813 $actual = \json_encode(['Mascott' => 'Beastie']);1814 $message = '';1815 $this->assertJsonStringNotEqualsJsonFile($file, $actual, $message);1816 }1817 public function testAssertJsonFileNotEqualsJsonFile(): void1818 {1819 $fileExpected = TEST_FILES_PATH . 'JsonData/simpleObject.json';1820 $fileActual = TEST_FILES_PATH . 'JsonData/arrayObject.json';1821 $message = '';1822 $this->assertJsonFileNotEqualsJsonFile($fileExpected, $fileActual, $message);1823 }1824 public function testAssertJsonFileEqualsJsonFile(): void1825 {1826 $file = TEST_FILES_PATH . 'JsonData/simpleObject.json';1827 $message = '';1828 $this->assertJsonFileEqualsJsonFile($file, $file, $message);1829 }1830 public function testAssertInstanceOfThrowsExceptionIfTypeDoesNotExist(): void1831 {1832 $this->expectException(Exception::class);1833 $this->assertInstanceOf('ClassThatDoesNotExist', new \stdClass);1834 }1835 public function testAssertInstanceOf(): void1836 {1837 $this->assertInstanceOf(\stdClass::class, new \stdClass);1838 $this->expectException(AssertionFailedError::class);1839 $this->assertInstanceOf(\Exception::class, new \stdClass);1840 }1841 public function testAssertAttributeInstanceOf(): void1842 {1843 $o = new \stdClass;1844 $o->a = new \stdClass;1845 $this->assertAttributeInstanceOf(\stdClass::class, 'a', $o);1846 }1847 public function testAssertNotInstanceOfThrowsExceptionIfTypeDoesNotExist(): void1848 {1849 $this->expectException(Exception::class);1850 $this->assertNotInstanceOf('ClassThatDoesNotExist', new \stdClass);1851 }1852 public function testAssertNotInstanceOf(): void1853 {1854 $this->assertNotInstanceOf(\Exception::class, new \stdClass);1855 $this->expectException(AssertionFailedError::class);1856 $this->assertNotInstanceOf(\stdClass::class, new \stdClass);1857 }1858 public function testAssertAttributeNotInstanceOf(): void1859 {1860 $o = new \stdClass;1861 $o->a = new \stdClass;1862 $this->assertAttributeNotInstanceOf(\Exception::class, 'a', $o);1863 }1864 public function testAssertInternalType(): void1865 {1866 $this->assertInternalType('integer', 1);1867 $this->expectException(AssertionFailedError::class);1868 $this->assertInternalType('string', 1);1869 }1870 public function testAssertInternalTypeDouble(): void1871 {1872 $this->assertInternalType('double', 1.0);1873 $this->expectException(AssertionFailedError::class);1874 $this->assertInternalType('double', 1);1875 }1876 public function testAssertAttributeInternalType(): void1877 {1878 $o = new \stdClass;1879 $o->a = 1;1880 $this->assertAttributeInternalType('integer', 'a', $o);1881 }1882 public function testAssertNotInternalType(): void1883 {1884 $this->assertNotInternalType('string', 1);1885 $this->expectException(AssertionFailedError::class);1886 $this->assertNotInternalType('integer', 1);1887 }1888 public function testAssertAttributeNotInternalType(): void1889 {1890 $o = new \stdClass;1891 $o->a = 1;1892 $this->assertAttributeNotInternalType('string', 'a', $o);1893 }1894 public function testAssertStringMatchesFormatFileThrowsExceptionForInvalidArgument(): void1895 {1896 $this->expectException(Exception::class);1897 $this->assertStringMatchesFormatFile('not_existing_file', '');1898 }1899 public function testAssertStringMatchesFormatFile(): void1900 {1901 $this->assertStringMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "FOO\n");1902 $this->expectException(AssertionFailedError::class);1903 $this->assertStringMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "BAR\n");1904 }1905 public function testAssertStringNotMatchesFormatFileThrowsExceptionForInvalidArgument(): void1906 {1907 $this->expectException(Exception::class);1908 $this->assertStringNotMatchesFormatFile('not_existing_file', '');1909 }1910 public function testAssertStringNotMatchesFormatFile(): void1911 {1912 $this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "BAR\n");1913 $this->expectException(AssertionFailedError::class);1914 $this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "FOO\n");1915 }1916 public function testStringsCanBeComparedForEqualityIgnoringCase(): void1917 {1918 $this->assertEqualsIgnoringCase('a', 'A');1919 $this->assertNotEqualsIgnoringCase('a', 'B');1920 }1921 public function testArraysOfStringsCanBeComparedForEqualityIgnoringCase(): void1922 {1923 $this->assertEqualsIgnoringCase(['a'], ['A']);1924 $this->assertNotEqualsIgnoringCase(['a'], ['B']);1925 }1926 public function testStringsCanBeComparedForEqualityWithDelta(): void1927 {1928 $this->assertEqualsWithDelta(2.3, 2.5, 0.5);1929 $this->assertNotEqualsWithDelta(2.3, 3.5, 0.5);1930 }1931 public function testArraysOfStringsCanBeComparedForEqualityWithDelta(): void1932 {1933 $this->assertEqualsWithDelta([2.3], [2.5], 0.5);1934 $this->assertNotEqualsWithDelta([2.3], [3.5], 0.5);1935 }1936 public function testArraysCanBeComparedForEqualityWithCanonicalization(): void1937 {1938 $this->assertEqualsCanonicalizing([3, 2, 1], [2, 3, 1]);1939 $this->assertNotEqualsCanonicalizing([3, 2, 1], [2, 3, 4]);1940 }1941 public function testArrayTypeCanBeAsserted(): void1942 {1943 $this->assertIsArray([]);1944 try {1945 $this->assertIsArray(null);1946 } catch (AssertionFailedError $e) {1947 return;1948 }1949 $this->fail();1950 }1951 public function testBoolTypeCanBeAsserted(): void1952 {1953 $this->assertIsBool(true);1954 try {1955 $this->assertIsBool(null);1956 } catch (AssertionFailedError $e) {1957 return;1958 }1959 $this->fail();1960 }1961 public function testFloatTypeCanBeAsserted(): void1962 {1963 $this->assertIsFloat(0.0);1964 try {1965 $this->assertIsFloat(null);1966 } catch (AssertionFailedError $e) {1967 return;1968 }1969 $this->fail();1970 }1971 public function testIntTypeCanBeAsserted(): void1972 {1973 $this->assertIsInt(1);1974 try {1975 $this->assertIsInt(null);1976 } catch (AssertionFailedError $e) {1977 return;1978 }1979 $this->fail();1980 }1981 public function testNumericTypeCanBeAsserted(): void1982 {1983 $this->assertIsNumeric('1.0');1984 try {1985 $this->assertIsNumeric('abc');1986 } catch (AssertionFailedError $e) {1987 return;1988 }1989 $this->fail();1990 }1991 public function testObjectTypeCanBeAsserted(): void1992 {1993 $this->assertIsObject(new \stdClass);1994 try {1995 $this->assertIsObject(null);1996 } catch (AssertionFailedError $e) {1997 return;1998 }1999 $this->fail();2000 }2001 public function testResourceTypeCanBeAsserted(): void2002 {2003 $this->assertIsResource(\fopen(__FILE__, 'r'));2004 try {2005 $this->assertIsResource(null);2006 } catch (AssertionFailedError $e) {2007 return;2008 }2009 $this->fail();2010 }2011 public function testStringTypeCanBeAsserted(): void2012 {2013 $this->assertIsString('');2014 try {2015 $this->assertIsString(null);2016 } catch (AssertionFailedError $e) {2017 return;2018 }2019 $this->fail();2020 }2021 public function testScalarTypeCanBeAsserted(): void2022 {2023 $this->assertIsScalar(true);2024 try {2025 $this->assertIsScalar(new \stdClass);2026 } catch (AssertionFailedError $e) {2027 return;2028 }2029 $this->fail();2030 }2031 public function testCallableTypeCanBeAsserted(): void2032 {2033 $this->assertIsCallable(function () {2034 });2035 try {2036 $this->assertIsCallable(null);2037 } catch (AssertionFailedError $e) {2038 return;2039 }2040 $this->fail();2041 }2042 public function testIterableTypeCanBeAsserted(): void2043 {2044 $this->assertIsIterable([]);2045 try {2046 $this->assertIsIterable(null);2047 } catch (AssertionFailedError $e) {2048 return;2049 }2050 $this->fail();2051 }2052 public function testNotArrayTypeCanBeAsserted(): void2053 {2054 $this->assertIsNotArray(null);2055 try {2056 $this->assertIsNotArray([]);2057 } catch (AssertionFailedError $e) {2058 return;2059 }2060 $this->fail();2061 }2062 public function testNotBoolTypeCanBeAsserted(): void2063 {2064 $this->assertIsNotBool(null);2065 try {2066 $this->assertIsNotBool(true);2067 } catch (AssertionFailedError $e) {2068 return;2069 }2070 $this->fail();2071 }2072 public function testNotFloatTypeCanBeAsserted(): void2073 {2074 $this->assertIsNotFloat(null);2075 try {2076 $this->assertIsNotFloat(0.0);2077 } catch (AssertionFailedError $e) {2078 return;2079 }2080 $this->fail();2081 }2082 public function testNotIntTypeCanBeAsserted(): void2083 {2084 $this->assertIsNotInt(null);2085 try {2086 $this->assertIsNotInt(1);2087 } catch (AssertionFailedError $e) {2088 return;2089 }2090 $this->fail();2091 }2092 public function testNotNumericTypeCanBeAsserted(): void2093 {2094 $this->assertIsNotNumeric('abc');2095 try {2096 $this->assertIsNotNumeric('1.0');2097 } catch (AssertionFailedError $e) {2098 return;2099 }2100 $this->fail();2101 }2102 public function testNotObjectTypeCanBeAsserted(): void2103 {2104 $this->assertIsNotObject(null);2105 try {2106 $this->assertIsNotObject(new \stdClass);2107 } catch (AssertionFailedError $e) {2108 return;2109 }2110 $this->fail();2111 }2112 public function testNotResourceTypeCanBeAsserted(): void2113 {2114 $this->assertIsNotResource(null);2115 try {2116 $this->assertIsNotResource(\fopen(__FILE__, 'r'));2117 } catch (AssertionFailedError $e) {2118 return;2119 }2120 $this->fail();2121 }2122 public function testNotScalarTypeCanBeAsserted(): void2123 {2124 $this->assertIsNotScalar(new \stdClass);2125 try {2126 $this->assertIsNotScalar(true);2127 } catch (AssertionFailedError $e) {2128 return;2129 }2130 $this->fail();2131 }2132 public function testNotStringTypeCanBeAsserted(): void2133 {2134 $this->assertIsNotString(null);2135 try {2136 $this->assertIsNotString('');2137 } catch (AssertionFailedError $e) {2138 return;2139 }2140 $this->fail();2141 }2142 public function testNotCallableTypeCanBeAsserted(): void2143 {2144 $this->assertIsNotCallable(null);2145 try {2146 $this->assertIsNotCallable(function () {2147 });2148 } catch (AssertionFailedError $e) {2149 return;2150 }2151 $this->fail();2152 }2153 public function testNotIterableTypeCanBeAsserted(): void2154 {2155 $this->assertIsNotIterable(null);2156 try {2157 $this->assertIsNotIterable([]);2158 } catch (AssertionFailedError $e) {2159 return;2160 }2161 $this->fail();2162 }2163 public function testLogicalAnd(): void2164 {2165 $this->assertThat(2166 true,2167 $this->logicalAnd(2168 $this->isTrue(),2169 $this->isTrue()2170 )2171 );2172 $this->expectException(AssertionFailedError::class);2173 $this->assertThat(2174 true,2175 $this->logicalAnd(2176 $this->isTrue(),2177 $this->isFalse()2178 )2179 );2180 }2181 public function testLogicalOr(): void2182 {2183 $this->assertThat(2184 true,2185 $this->logicalOr(2186 $this->isTrue(),2187 $this->isFalse()2188 )2189 );2190 $this->expectException(AssertionFailedError::class);2191 $this->assertThat(2192 true,2193 $this->logicalOr(2194 $this->isFalse(),2195 $this->isFalse()2196 )2197 );2198 }2199 public function testLogicalXor(): void2200 {2201 $this->assertThat(2202 true,2203 $this->logicalXor(2204 $this->isTrue(),2205 $this->isFalse()2206 )2207 );2208 $this->expectException(AssertionFailedError::class);2209 $this->assertThat(2210 true,2211 $this->logicalXor(2212 $this->isTrue(),2213 $this->isTrue()2214 )2215 );2216 }2217 public function testStringContainsStringCanBeAsserted(): void2218 {2219 $this->assertStringContainsString('bar', 'foobarbaz');2220 try {2221 $this->assertStringContainsString('barbara', 'foobarbaz');2222 } catch (AssertionFailedError $e) {2223 return;2224 }2225 $this->fail();2226 }2227 public function testStringNotContainsStringCanBeAsserted(): void2228 {2229 $this->assertStringNotContainsString('barbara', 'foobarbaz');2230 try {2231 $this->assertStringNotContainsString('bar', 'foobarbaz');2232 } catch (AssertionFailedError $e) {2233 return;2234 }2235 $this->fail();2236 }2237 public function testStringContainsStringCanBeAssertedIgnoringCase(): void2238 {2239 $this->assertStringContainsStringIgnoringCase('BAR', 'foobarbaz');2240 try {2241 $this->assertStringContainsStringIgnoringCase('BARBARA', 'foobarbaz');2242 } catch (AssertionFailedError $e) {2243 return;2244 }2245 $this->fail();2246 }2247 public function testStringNotContainsStringCanBeAssertedIgnoringCase(): void2248 {2249 $this->assertStringNotContainsStringIgnoringCase('BARBARA', 'foobarbaz');2250 try {2251 $this->assertStringNotContainsStringIgnoringCase('BAR', 'foobarbaz');2252 } catch (AssertionFailedError $e) {2253 return;2254 }2255 $this->fail();2256 }2257 public function testIterableContainsSameObjectCanBeAsserted(): void2258 {2259 $object = new \stdClass;2260 $iterable = [$object];2261 $this->assertContains($object, $iterable);2262 try {2263 $this->assertContains(new \stdClass, $iterable);2264 } catch (AssertionFailedError $e) {2265 return;2266 }2267 $this->fail();2268 }2269 public function testIterableNotContainsSameObjectCanBeAsserted(): void2270 {2271 $object = new \stdClass;2272 $iterable = [$object];2273 $this->assertNotContains(new \stdClass, $iterable);2274 try {2275 $this->assertNotContains($object, $iterable);2276 } catch (AssertionFailedError $e) {2277 return;2278 }2279 $this->fail();2280 }2281 protected function sameValues(): array2282 {2283 $object = new \SampleClass(4, 8, 15);2284 $file = TEST_FILES_PATH . 'foo.xml';2285 $resource = \fopen($file, 'r');2286 return [2287 // null2288 [null, null],2289 // strings2290 ['a', 'a'],...
AssertionFailedError
Using AI Code Generation
1require_once 'PHPUnit/Framework/Assert/Functions.php';2require_once 'PHPUnit/Framework/TestCase.php';3require_once 'PHPUnit/Framework/TestSuite.php';4require_once 'PHPUnit/TextUI/TestRunner.php';5require_once 'PHPUnit/Util/Filter.php';6require_once '2.php';7require_once 'PHPUnit/Util/Test.php';8require_once 'PHPUnit/Framework/TestResult.php';9require_once 'PHPUnit/Framework/TestListener.php';10require_once 'PHPUnit/Framework/TestSuite.php';11require_once 'PHPUnit/Framework/Test.php';12require_once 'PHPUnit/Framework/AssertionFailedError.php';13require_once 'PHPUnit/Framework/Exception.php';14require_once 'PHPUnit/Framework/TestFailure.php';15require_once 'PHPUnit/Framework/TestListener.php';16require_once 'PHPUnit/Framework/TestResult.php';17require_once 'PHPUnit/Framework/TestSuite.php';18require_once 'PHPUnit/Framework/Warning.php';19require_once 'PHPUnit/TextUI/ResultPrinter.php';20require_once 'PHPUnit/TextUI/TestRunner.php';21require_once 'PHPUnit/Util/ErrorHandler.php';22require_once 'PHPUnit/Util/Filter.php';
AssertionFailedError
Using AI Code Generation
1use PHPUnit\Framework\TestCase;2use PHPUnit\Framework\AssertionFailedError;3{4 public function testAssert()5 {6 $this->assertEquals(1, 2);7 }8}9use PHPUnit\Framework\TestCase;10use PHPUnit\Framework\Assert;11{12 public function testAssert()13 {14 Assert::assertEquals(1, 2);15 }16}17use PHPUnit\Framework\TestCase;18use PHPUnit\Framework\Assert;19{20 public function testAssert()21 {22 $this->assertTrue(false);23 }24}
AssertionFailedError
Using AI Code Generation
1use PHPUnit\Framework\AssertionFailedError;2{3 public function testAssertStringContainsString()4 {5 $this->assertStringContainsString('foo', 'foobar');6 }7}8use PHPUnit\Framework\AssertionFailedError;9{10 public function testAssertStringContainsString()11 {12 $this->assertStringContainsString('foo', 'foobar');13 }14}15use PHPUnit\Framework\AssertionFailedError;16{17 public function testAssertStringContainsString()18 {19 $this->assertStringContainsString('foo', 'foobar');20 }21}22use PHPUnit\Framework\AssertionFailedError;23{24 public function testAssertStringContainsString()25 {26 $this->assertStringContainsString('foo', 'foobar');27 }28}29use PHPUnit\Framework\AssertionFailedError;30{31 public function testAssertStringContainsString()32 {33 $this->assertStringContainsString('foo', 'foobar');34 }35}36use PHPUnit\Framework\AssertionFailedError;37{38 public function testAssertStringContainsString()39 {40 $this->assertStringContainsString('foo', 'foobar');41 }42}43use PHPUnit\Framework\AssertionFailedError;44{45 public function testAssertStringContainsString()46 {47 $this->assertStringContainsString('foo', 'foobar');48 }49}50use PHPUnit\Framework\AssertionFailedError;51{52 public function testAssertStringContainsString()53 {
AssertionFailedError
Using AI Code Generation
1use PHPUnit\Framework\AssertionFailedError;2{3 use \PHPUnit\Framework\Assert;4 public function testOne()5 {6 $this->assertFileExists('/path/to/file');7 }8}9assertFileNotExists() method10public void assertFileNotExists ( string $filename [, string $message = '' ] )11use PHPUnit\Framework\AssertionFailedError;12{13 use \PHPUnit\Framework\Assert;14 public function testOne()15 {16 $this->assertFileNotExists('/path/to/file');17 }18}19OK (1 test, 1 assertion)20assertDirectoryExists() method
AssertionFailedError
Using AI Code Generation
1require_once 'PHPUnit/Framework/Assert/Functions.php';2require_once 'PHPUnit/Framework/Assert.php';3PHPUnit_Framework_Assert::fail('test failed');4require_once 'PHPUnit/Framework/Assert/Functions.php';5fail('test failed');6require_once 'PHPUnit/Framework/Assert.php';
AssertionFailedError
Using AI Code Generation
1class Test extends PHPUnit_Framework_TestCase {2 public function testFailure() {3 $this->assertStringStartsWith('foo', 'bar');4 }5}6assertStringStartsWith(string $prefix, string $string, string $message = '')7class Test extends PHPUnit_Framework_TestCase {8 public function testFailure() {9 $this->assertStringStartsWith('foo', 'foobar');10 }11}12OK (1 test, 1 assertion)13assertStringEndsWith(string $suffix, string $string, string $message = '')
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!