diff --git a/.php_cs b/.php_cs index 725a3035..d163e603 100644 --- a/.php_cs +++ b/.php_cs @@ -3,7 +3,6 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'bin') - ->in(__DIR__ . DIRECTORY_SEPARATOR . 'compiled') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'scripts') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') diff --git a/src/Expectation.php b/src/Expectation.php index db123468..0aaf2159 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -62,6 +62,16 @@ final class Expectation return $this; } + /** + * Assert the value is true. + */ + public function toBeTrue(): Expectation + { + Assert::assertTrue($this->value); + + return $this; + } + /** * Assert the value is false. */ @@ -123,54 +133,15 @@ final class Expectation /** * Assert that needles is an element of value. * - * @param mixed $needle + * @param mixed $value */ - public function toContain($needle): Expectation + public function toContain($value): Expectation { - Assert::assertContains($needle, $this->value); - - return $this; - } - - /** - * Assert the value contains only variables of type. - * - * @param mixed $type - */ - public function toContainOnly($type): Expectation - { - Assert::assertContainsOnly($type, $this->value); - - return $this; - } - - /** - * Assert the value contains only instances of $instance. - */ - public function toContainOnlyInstancesOf(string $instance): Expectation - { - Assert::assertContainsOnlyInstancesOf($instance, $this->value); - - return $this; - } - - /** - * Assert that needles is a substring of value. - */ - public function toContainString(string $needle): Expectation - { - Assert::assertStringContainsString($needle, $this->value); - - return $this; - } - - /** - * Assert that needles is a substring of value, ignoring the - * difference in casing. - */ - public function toContainStringIgnoringCase(string $needle): Expectation - { - Assert::assertStringContainsStringIgnoringCase($needle, $this->value); + if (is_string($value)) { + Assert::assertStringContainsString($value, $this->value); + } else { + Assert::assertContains($value, $this->value); + } return $this; } @@ -178,7 +149,7 @@ final class Expectation /** * Assert that $count matches the number of elements of $value. */ - public function toCount(int $count): Expectation + public function toHaveCount(int $count): Expectation { Assert::assertCount($count, $this->value); @@ -234,7 +205,7 @@ final class Expectation * * @param mixed $value */ - public function toEqualWithDelta($value, float $delta): Expectation + public function toBeEqualWithDelta($value, float $delta): Expectation { Assert::assertEqualsWithDelta($value, $this->value, $delta); @@ -254,11 +225,12 @@ final class Expectation /** * Assert that the value is an instance of $value. * - * @param mixed $value + * @param string $class */ - public function toBeInstanceOf($value): Expectation + public function toBeInstanceOf($class): Expectation { - Assert::assertInstanceOf($value, $this->value); + /* @phpstan-ignore-next-line */ + Assert::assertInstanceOf($class, $this->value); return $this; } @@ -384,7 +356,7 @@ final class Expectation } /** - * Assert that the value is NAN. + * Assert that the value is null. */ public function toBeNull(): Expectation { diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index e0b7f1c4..a6c9b499 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest\PendingObjects; use Closure; +use Pest\Expectation; use Pest\Factories\TestCaseFactory; use Pest\Support\Backtrace; use Pest\Support\NullClosure; @@ -84,6 +85,16 @@ final class TestCall return $this; } + /** + * Creates a new expectation. + * + * @param mixed $value the Value + */ + public function expect($value): Expectation + { + return expect($value); + } + /** * Sets the test depends. */ diff --git a/src/globals.php b/src/globals.php index 07ec9d6e..59e5e784 100644 --- a/src/globals.php +++ b/src/globals.php @@ -108,6 +108,8 @@ function afterAll(Closure $closure = null): void /** * Creates a new expectation. + * + * @param mixed $value the Value */ function expect($value): Expectation { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 916c0d6c..6f9ce702 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -110,31 +110,16 @@ PASS Tests\Expect\toBeString ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeTrue + ✓ strict comparisons + ✓ failures ✓ not failures PASS Tests\Expect\toContain ✓ passes ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainOnly - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainOnlyInstancesOf - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainString - ✓ is case sensitive - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainStringIgnoringCase - ✓ ignore difference in casing - ✓ failures ✓ not failures PASS Tests\Expect\toCount @@ -231,9 +216,9 @@ PASS Tests\Features\HigherOrderTests ✓ it proxies calls to object - PASS Tests\Features\It + WARN Tests\Features\It ✓ it is a test - ✓ it is a higher order message test + ! it is a higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4 PASS Tests\Features\Macro ✓ it can call chained macro method @@ -243,8 +228,8 @@ ✓ it has bar PASS Tests\Features\PendingHigherOrderTests - ✓ get 'foo' → get 'bar' → assertTrue true - ✓ get 'foo' → assertTrue true + ✓ get 'foo' → get 'bar' + ✓ get 'foo' WARN Tests\Features\Skip ✓ it do not skips @@ -255,9 +240,9 @@ ✓ it do not skips with falsy closure condition - it skips with condition and message → skipped because foo - PASS Tests\Features\Test + WARN Tests\Features\Test ✓ a test - ✓ higher order message test + ! higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4 PASS Tests\Fixtures\DirectoryWithTests\ExampleTest ✓ it example 1 @@ -327,5 +312,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 192 passed - Time: 5.20s + Tests: 2 risked, 6 skipped, 181 passed + Time: 5.72s diff --git a/tests/Autoload.php b/tests/Autoload.php index 9283dbad..1e181ad2 100644 --- a/tests/Autoload.php +++ b/tests/Autoload.php @@ -8,7 +8,7 @@ trait PluginTrait { public function assertPluginTraitGotRegistered(): void { - assertTrue(true); + $this->assertTrue(true); } } @@ -16,7 +16,7 @@ trait SecondPluginTrait { public function assertSecondPluginTraitGotRegistered(): void { - assertTrue(true); + $this->assertTrue(true); } } diff --git a/tests/Expect/toBeTrue.php b/tests/Expect/toBeTrue.php new file mode 100644 index 00000000..8e998f9b --- /dev/null +++ b/tests/Expect/toBeTrue.php @@ -0,0 +1,15 @@ +toBeTrue(); +}); + +test('failures', function () { + expect('')->toBeTrue(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(false)->not->toBe(false); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainOnly.php b/tests/Expect/toContainOnly.php deleted file mode 100644 index 2e9fecfe..00000000 --- a/tests/Expect/toContainOnly.php +++ /dev/null @@ -1,17 +0,0 @@ -toContainOnly('int'); - expect(['hello', 'world'])->toContainOnly('string'); -}); - -test('failures', function () { - expect([1, 2, '3'])->toContainOnly('string'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect([1, 2, 3])->not->toContainOnly('int'); - expect(['hello', 'world'])->not->toContainOnly('string'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainOnlyInstancesOf.php b/tests/Expect/toContainOnlyInstancesOf.php deleted file mode 100644 index fdda161b..00000000 --- a/tests/Expect/toContainOnlyInstancesOf.php +++ /dev/null @@ -1,23 +0,0 @@ -toContainOnlyInstancesOf(Expectation::class); -}); - -test('failures', function () { - $expected = [new Expectation('whatever')]; - - expect($expected)->toContainOnlyInstancesOf(AddsTests::class); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - $expected = [new Expectation('whatever')]; - - expect($expected)->not->toContainOnlyInstancesOf(Expectation::class); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainString.php b/tests/Expect/toContainString.php deleted file mode 100644 index 03f55b69..00000000 --- a/tests/Expect/toContainString.php +++ /dev/null @@ -1,16 +0,0 @@ -toContainString('world'); - expect('hello world')->not->toContainString('World'); -}); - -test('failures', function () { - expect('hello world')->toContainString('Hello'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('hello world')->not->toContainString('hello'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainStringIgnoringCase.php b/tests/Expect/toContainStringIgnoringCase.php deleted file mode 100644 index fc5e1081..00000000 --- a/tests/Expect/toContainStringIgnoringCase.php +++ /dev/null @@ -1,17 +0,0 @@ -toContainStringIgnoringCase('world'); - expect('hello world')->toContainStringIgnoringCase('World'); -}); - -test('failures', function () { - expect('hello world')->toContainStringIgnoringCase('hi'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('hello world')->not->toContainStringIgnoringCase('Hello'); - expect('hello world')->not->toContainStringIgnoringCase('hello'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toCount.php b/tests/Expect/toCount.php index 6e8d5fcd..a1948260 100644 --- a/tests/Expect/toCount.php +++ b/tests/Expect/toCount.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect([1, 2, 3])->toCount(3); + expect([1, 2, 3])->toHaveCount(3); }); test('failures', function () { - expect([1, 2, 3])->toCount(4); + expect([1, 2, 3])->toHaveCount(4); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect([1, 2, 3])->not->toCount(3); + expect([1, 2, 3])->not->toHaveCount(3); })->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqualWithDelta.php b/tests/Expect/toEqualWithDelta.php index bb78b86d..3faab6e2 100644 --- a/tests/Expect/toEqualWithDelta.php +++ b/tests/Expect/toEqualWithDelta.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(1.0)->toEqualWithDelta(1.3, .4); + expect(1.0)->toBeEqualWithDelta(1.3, .4); }); test('failures', function () { - expect(1.0)->toEqualWithDelta(1.5, .1); + expect(1.0)->toBeEqualWithDelta(1.5, .1); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(1.0)->not->toEqualWithDelta(1.6, .7); + expect(1.0)->not->toBeEqualWithDelta(1.6, .7); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/AfterAll.php b/tests/Features/AfterAll.php index e78e12a5..1b66792e 100644 --- a/tests/Features/AfterAll.php +++ b/tests/Features/AfterAll.php @@ -8,8 +8,8 @@ afterAll(function () use ($file) { test('deletes file after all', function () use ($file) { file_put_contents($file, 'foo'); - assertFileExists($file); + $this->assertFileExists($file); register_shutdown_function(function () use ($file) { - assertFileNotExists($file); + $this->assertFileNotExists($file); }); }); diff --git a/tests/Features/AfterEach.php b/tests/Features/AfterEach.php index 4563e717..5c223833 100644 --- a/tests/Features/AfterEach.php +++ b/tests/Features/AfterEach.php @@ -11,10 +11,10 @@ afterEach(function () use ($state) { }); it('does not get executed before the test', function () { - assertFalse(property_exists($this->state, 'bar')); + expect(property_exists($this->state, 'bar'))->toBeFalse(); }); it('gets executed after the test', function () { - assertTrue(property_exists($this->state, 'bar')); - assertEquals(2, $this->state->bar); + expect(property_exists($this->state, 'bar'))->toBeTrue(); + expect($this->state->bar)->toBe(2); }); diff --git a/tests/Features/BeforeAll.php b/tests/Features/BeforeAll.php index 4095e68a..e8e458bc 100644 --- a/tests/Features/BeforeAll.php +++ b/tests/Features/BeforeAll.php @@ -8,11 +8,11 @@ beforeAll(function () use ($foo) { }); it('gets executed before tests', function () use ($foo) { - assertEquals($foo->bar, 1); + expect($foo->bar)->toBe(1); $foo->bar = 'changed'; }); it('do not get executed before each test', function () use ($foo) { - assertEquals($foo->bar, 'changed'); + expect($foo->bar)->toBe('changed'); }); diff --git a/tests/Features/BeforeEach.php b/tests/Features/BeforeEach.php index 94c5adc3..a2e70d61 100644 --- a/tests/Features/BeforeEach.php +++ b/tests/Features/BeforeEach.php @@ -5,11 +5,11 @@ beforeEach(function () { }); it('gets executed before each test', function () { - assertEquals($this->bar, 2); + expect($this->bar)->toBe(2); $this->bar = 'changed'; }); it('gets executed before each test once again', function () { - assertEquals($this->bar, 2); + expect($this->bar)->toBe(2); }); diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index 35764433..81f41b34 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -23,13 +23,13 @@ it('sets closures', function () { yield [1]; }); - assertEquals([[1]], iterator_to_array(Datasets::get('foo')())); + expect(iterator_to_array(Datasets::get('foo')()))->toBe([[1]]); }); it('sets arrays', function () { Datasets::set('bar', [[2]]); - assertEquals([[2]], Datasets::get('bar')); + expect(Datasets::get('bar'))->toBe([[2]]); }); it('gets bound to test case object', function () { @@ -37,7 +37,7 @@ it('gets bound to test case object', function () { })->with([['a'], ['b']]); test('it truncates the description', function () { - assertTrue(true); + expect(true)->toBe(true); // it gets tested by the integration test })->with([str_repeat('Fooo', 10000000)]); @@ -48,51 +48,51 @@ $datasets = [[1], [2]]; test('lazy datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect(in_array([$text], $datasets))->toBe(true); })->with($datasets); test('lazy datasets did the job right', function () use ($state) { - assertEquals('12', $state->text); + expect($state->text)->toBe('12'); }); $state->text = ''; test('eager datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with(function () use ($datasets) { return $datasets; }); test('eager datasets did the job right', function () use ($state) { - assertEquals('1212', $state->text); + expect($state->text)->toBe('1212'); }); test('lazy registered datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with('numbers.array'); test('lazy registered datasets did the job right', function () use ($state) { - assertEquals('121212', $state->text); + expect($state->text)->toBe('121212'); }); test('eager registered datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with('numbers.closure'); test('eager registered datasets did the job right', function () use ($state) { - assertEquals('12121212', $state->text); + expect($state->text)->toBe('12121212'); }); test('eager wrapped registered datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with('numbers.closure.wrapped'); test('eager registered wrapped datasets did the job right', function () use ($state) { - assertEquals('1212121212', $state->text); + expect($state->text)->toBe('1212121212'); }); class Bar @@ -105,13 +105,13 @@ $namedDatasets = [ ]; test('lazy named datasets', function ($text) use ($state, $datasets) { - assertTrue(true); + expect(true)->toBeTrue(); })->with($namedDatasets); $counter = 0; it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) { - assertTrue(true); + expect(true)->toBeTrue(); $counter++; })->with([ ['Name 1', new Plugin(), true], @@ -123,5 +123,5 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo ]); it('creates unique test case names - count', function () use (&$counter) { - assertEquals(6, $counter); + expect($counter)->toBe(6); }); diff --git a/tests/Features/Depends.php b/tests/Features/Depends.php index 0e7ed5ea..edab5956 100644 --- a/tests/Features/Depends.php +++ b/tests/Features/Depends.php @@ -3,38 +3,32 @@ $runCounter = 0; test('first', function () use (&$runCounter) { - assertTrue(true); + expect(true)->toBeTrue(); $runCounter++; return 'first'; }); test('second', function () use (&$runCounter) { - assertTrue(true); + expect(true)->toBeTrue(); $runCounter++; return 'second'; }); test('depends', function () { - assertEquals( - ['first', 'second'], - func_get_args() - ); + expect(func_get_args())->toBe(['first', 'second']); })->depends('first', 'second'); test('depends with ...params', function (string ...$params) { - assertEquals( - ['first', 'second'], - $params - ); + expect(func_get_args())->toBe($params); })->depends('first', 'second'); test('depends with defined arguments', function (string $first, string $second) { - assertEquals('first', $first); - assertEquals('second', $second); + expect($first)->toBe('first'); + expect($second)->toBe('second'); })->depends('first', 'second'); test('depends run test only once', function () use (&$runCounter) { - assertEquals(2, $runCounter); + expect($runCounter)->toBe(2); })->depends('first', 'second'); diff --git a/tests/Features/Helpers.php b/tests/Features/Helpers.php index 24377e00..163ede9d 100644 --- a/tests/Features/Helpers.php +++ b/tests/Features/Helpers.php @@ -7,7 +7,7 @@ function addUser() it('can set/get properties on $this', function () { addUser(); - assertEquals('nuno', $this->user); + expect($this->user)->toBe('nuno'); }); it('throws error if property do not exist', function () { @@ -27,15 +27,14 @@ function mockUser() $mock = test()->createMock(User::class); $mock->method('getName') - ->willReturn('maduro'); + ->willReturn('maduro'); return $mock; } it('allows to call underlying protected/private methods', function () { $user = mockUser(); - - assertEquals('maduro', $user->getName()); + expect($user->getName())->toBe('maduro'); }); it('throws error if method do not exist', function () { diff --git a/tests/Features/It.php b/tests/Features/It.php index 9ab6e384..384e12bd 100644 --- a/tests/Features/It.php +++ b/tests/Features/It.php @@ -1,7 +1,7 @@ 'foo']); + $this->assertArrayHasKey('key', ['key' => 'foo']); }); -it('is a higher order message test')->assertTrue(true); +it('is a higher order message test')->expect(true)->toBeTrue(); diff --git a/tests/Features/Macro.php b/tests/Features/Macro.php index fa9f63ee..c0893355 100644 --- a/tests/Features/Macro.php +++ b/tests/Features/Macro.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; uses(Macroable::class); beforeEach()->macro('bar', function () { - assertInstanceOf(TestCase::class, $this); + expect($this)->toBeInstanceOf(TestCase::class); }); it('can call chained macro method')->bar(); diff --git a/tests/Features/PendingHigherOrderTests.php b/tests/Features/PendingHigherOrderTests.php index de178c51..cf68dcc6 100644 --- a/tests/Features/PendingHigherOrderTests.php +++ b/tests/Features/PendingHigherOrderTests.php @@ -1,11 +1,12 @@ not->toBeEmpty(); return $this; } } -get('foo')->get('bar')->assertTrue(true); -get('foo')->assertTrue(true); +get('foo')->get('bar')->expect(true)->toBeTrue(); +get('foo')->expect(true)->toBeTrue(); diff --git a/tests/Features/Test.php b/tests/Features/Test.php index d2e53ed0..e3334305 100644 --- a/tests/Features/Test.php +++ b/tests/Features/Test.php @@ -1,7 +1,7 @@ 'foo']); + $this->assertArrayHasKey('key', ['key' => 'foo']); }); -test('higher order message test')->assertTrue(true); +test('higher order message test')->expect(true)->toBeTrue(); diff --git a/tests/Features/TestCycle.php b/tests/Features/TestCycle.php index d941dcf2..efca9588 100644 --- a/tests/Features/TestCycle.php +++ b/tests/Features/TestCycle.php @@ -20,8 +20,8 @@ afterAll(function () { }); register_shutdown_function(function () use ($foo) { - assertFalse($foo->beforeAll); - assertFalse($foo->beforeEach); - assertFalse($foo->afterEach); - assertFalse($foo->afterAll); + expect($foo->beforeAll)->toBeFalse(); + expect($foo->beforeEach)->toBeFalse(); + expect($foo->afterEach)->toBeFalse(); + expect($foo->afterAll)->toBeFalse(); }); diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php index 2cd2999d..ee6b1489 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php @@ -10,6 +10,6 @@ class CustomTestCaseInSubFolder extends TestCase { public function assertCustomInSubFolderTrue() { - assertTrue(true); + $this->assertTrue(true); } } diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php index e0673174..8e582bcf 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php @@ -12,7 +12,7 @@ class MyCustomClass extends PHPUnit\Framework\TestCase { public function assertTrueIsTrue() { - assertTrue(true); + $this->assertTrue(true); } } diff --git a/tests/Playground.php b/tests/Playground.php index e24277b1..be30ae7d 100644 --- a/tests/Playground.php +++ b/tests/Playground.php @@ -1,5 +1,5 @@ toBeTrue(); }); diff --git a/tests/Unit/Actions/AddsDefaults.php b/tests/Unit/Actions/AddsDefaults.php index 7a55adc5..eef7b027 100644 --- a/tests/Unit/Actions/AddsDefaults.php +++ b/tests/Unit/Actions/AddsDefaults.php @@ -7,14 +7,14 @@ use PHPUnit\TextUI\DefaultResultPrinter; it('sets defaults', function () { $arguments = AddsDefaults::to(['bar' => 'foo']); - assertInstanceOf(Printer::class, $arguments['printer']); - assertEquals($arguments['bar'], 'foo'); + expect($arguments['printer'])->toBeInstanceOf(Printer::class); + expect($arguments['bar'])->toBe('foo'); }); it('does not override options', function () { $defaultResultPrinter = new DefaultResultPrinter(); - assertEquals(AddsDefaults::to(['printer' => $defaultResultPrinter]), [ + expect(AddsDefaults::to(['printer' => $defaultResultPrinter]))->tobe([ 'printer' => $defaultResultPrinter, ]); }); diff --git a/tests/Unit/Actions/AddsTests.php b/tests/Unit/Actions/AddsTests.php index 925e3574..9f1beec0 100644 --- a/tests/Unit/Actions/AddsTests.php +++ b/tests/Unit/Actions/AddsTests.php @@ -16,10 +16,10 @@ test('default php unit tests', function () { $phpUnitTestCase = new class() extends PhpUnitTestCase { }; $testSuite->addTest($phpUnitTestCase); - assertCount(1, $testSuite->tests()); + expect($testSuite->tests())->toHaveCount(1); AddsTests::to($testSuite, new \Pest\TestSuite(getcwd())); - assertCount(1, $testSuite->tests()); + expect($testSuite->tests())->toHaveCount(1); }); it('removes warnings', function () use ($pestTestCase) { @@ -28,5 +28,5 @@ it('removes warnings', function () use ($pestTestCase) { $testSuite->addTest($warningTestCase); AddsTests::to($testSuite, new \Pest\TestSuite(getcwd())); - assertCount(0, $testSuite->tests()); + expect($testSuite->tests())->toHaveCount(0); }); diff --git a/tests/Unit/Actions/ValidatesConfiguration.php b/tests/Unit/Actions/ValidatesConfiguration.php index 24edc4f0..a26a4105 100644 --- a/tests/Unit/Actions/ValidatesConfiguration.php +++ b/tests/Unit/Actions/ValidatesConfiguration.php @@ -38,5 +38,5 @@ it('do not throws exception when `process isolation` is false', function () { 'configuration' => $filename, ]); - assertTrue(true); + expect(true)->toBeTrue(); }); diff --git a/tests/Unit/Plugins/Version.php b/tests/Unit/Plugins/Version.php index 0bd19052..0bd5feb7 100644 --- a/tests/Unit/Plugins/Version.php +++ b/tests/Unit/Plugins/Version.php @@ -8,7 +8,7 @@ it('outputs the version when --version is used', function () { $plugin = new Version($output); $plugin->handleArguments(['foo', '--version']); - assertStringContainsString('Pest 0.2.2', $output->fetch()); + expect($output->fetch())->toContain('Pest 0.2.2'); }); it('do not outputs version when --version is not used', function () { @@ -16,5 +16,5 @@ it('do not outputs version when --version is not used', function () { $plugin = new Version($output); $plugin->handleArguments(['foo', 'bar']); - assertEquals('', $output->fetch()); + expect($output->fetch())->toBe(''); }); diff --git a/tests/Unit/Support/Backtrace.php b/tests/Unit/Support/Backtrace.php index 55886512..6dba0ed5 100644 --- a/tests/Unit/Support/Backtrace.php +++ b/tests/Unit/Support/Backtrace.php @@ -7,5 +7,5 @@ it('gets file name from called file', function () { return Backtrace::file(); }; - assertEquals(__FILE__, $a()); + expect($a())->toBe(__FILE__); }); diff --git a/tests/Unit/Support/Container.php b/tests/Unit/Support/Container.php index 13a369ff..f42ba030 100644 --- a/tests/Unit/Support/Container.php +++ b/tests/Unit/Support/Container.php @@ -15,32 +15,32 @@ it('exists') it('gets an instance', function () { $this->container->add(Container::class, $this->container); - assertSame($this->container, $this->container->get(Container::class)); + expect($this->container->get(Container::class))->toBe($this->container); }); test('autowire', function () { - assertInstanceOf(Container::class, $this->container->get(Container::class)); + expect($this->container->get(Container::class))->toBeInstanceOf(Container::class); }); it('creates an instance and resolves parameters', function () { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithDependency::class); - assertInstanceOf(ClassWithDependency::class, $instance); + expect($instance)->toBeInstanceOf(ClassWithDependency::class); }); it('creates an instance and resolves also sub parameters', function () { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithSubDependency::class); - assertInstanceOf(ClassWithSubDependency::class, $instance); + expect($instance)->toBeInstanceOf(ClassWithSubDependency::class); }); it('can resolve builtin value types', function () { $this->container->add('rootPath', getcwd()); $instance = $this->container->get(TestSuite::class); - assertInstanceOf(TestSuite::class, $instance); + expect($instance)->toBeInstanceOf(TestSuite::class); }); it('cannot resolve a parameter without type', function () { diff --git a/tests/Unit/Support/Reflection.php b/tests/Unit/Support/Reflection.php index 56d5515a..7ad76b0d 100644 --- a/tests/Unit/Support/Reflection.php +++ b/tests/Unit/Support/Reflection.php @@ -3,9 +3,10 @@ use Pest\Support\Reflection; it('gets file name from closure', function () { - $fileName = Reflection::getFileNameFromClosure(function () {}); + $fileName = Reflection::getFileNameFromClosure(function () { + }); - assertEquals(__FILE__, $fileName); + expect($fileName)->toBe(__FILE__); }); it('gets property values', function () { @@ -15,5 +16,5 @@ it('gets property values', function () { $value = Reflection::getPropertyValue($class, 'foo'); - assertEquals('bar', $value); + expect($value)->toBe('bar'); }); diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 893caf3a..ef5ab6fa 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -10,7 +10,7 @@ $run = function (string $target, $decorated = false) { return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; -$snapshot = function ($name) { +$snapshot = function ($name) { $testsPath = dirname(__DIR__); return file_get_contents(implode(DIRECTORY_SEPARATOR, [ @@ -21,23 +21,15 @@ $snapshot = function ($name) { }; test('allows to run a single test', function () use ($run, $snapshot) { - assertStringContainsString( - $snapshot('allows-to-run-a-single-test'), - $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php')); + expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'))->toContain($snapshot('allows-to-run-a-single-test')); })->skip(PHP_OS_FAMILY === 'Windows'); test('allows to run a directory', function () use ($run, $snapshot) { - assertStringContainsString( - $snapshot('allows-to-run-a-directory'), - $run('tests/Fixtures') - ); + expect($run('tests/Fixtures'))->toContain($snapshot('allows-to-run-a-directory')); })->skip(PHP_OS_FAMILY === 'Windows'); it('has ascii chars', function () use ($run, $snapshot) { - assertStringContainsString( - $snapshot('has-ascii-chars'), - $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true) - ); + expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true))->toContain($snapshot('has-ascii-chars')); })->skip(PHP_OS_FAMILY === 'Windows'); it('disable decorating printer when colors is set to never', function () use ($snapshot) { @@ -49,9 +41,5 @@ it('disable decorating printer when colors is set to never', function () use ($s ], dirname(__DIR__, 2)); $process->run(); $output = $process->getOutput(); - - assertStringContainsString( - $snapshot('disable-decorating-printer'), - $output - ); + expect($output)->toContain($snapshot('disable-decorating-printer')); })->skip(PHP_OS_FAMILY === 'Windows'); diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index 97cbee6a..a4f5fae6 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -22,7 +22,7 @@ test('visual snapshot of test suite on success', function () { $output = explode("\n", $output()); array_pop($output); array_pop($output); - assertStringContainsString(implode("\n", $output), file_get_contents($snapshot)); + expect(file_get_contents($snapshot))->toContain(implode("\n", $output)); } })->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')) ->skip(PHP_OS_FAMILY === 'Windows');