diff --git a/README.md b/README.md index 6078a58..ef7d5fc 100644 --- a/README.md +++ b/README.md @@ -97,13 +97,6 @@ Laravel-specific Testing Helpers and Assertions. - [dontSeeLogFile](#dontseelogfile) - [seeInLogFile](#seeinlogfile) - [dontSeeInLogFile](#dontseeinlogfile) -- [ReflectionAsserts](#reflectionasserts) - - [assertSubclassOf](#assertsubclassof) - - [assertNotSubclassOf](#assertnotsubclassof) - - [assertTraitUsed](#asserttraitused) - - [assertTraitNotUsed](#asserttraitnotused) - - [assertMethodExists](#assertmethodexists) - - [assertMethodNotExists](#assertmethodnotexists) - [ScheduleAsserts](#scheduleasserts) - [seeScheduleCount](#seeschedulecount) - [dontSeeScheduleCount](#dontseeschedulecount) @@ -307,56 +300,6 @@ $this->dontSeeInLogFile('example.log', [ ]); ``` -### ReflectionAsserts - -#### `assertSubclassOf()` - -Assert that class is a subclass of the given parent: - -```php -$this->assertSubclassOf(Post::class, Model::class); -``` - -#### `assertNotSubclassOf()` - -Assert that class is not a subclass of the given parent: - -```php -$this->assertNotSubclassOf(Post::class, Command::class); -``` - -#### `assertTraitUsed()` - -Assert that class uses the given trait: - -```php -$this->assertTraitUsed(User::class, Notifiable::class); -``` - -#### `assertTraitNotUsed()` - -Assert that class doesn't use the given trait: - -```php -$this->assertTraitNotUsed(Post::class, Notifiable::class); -``` - -#### `assertMethodExists()` - -Assert that object has the given method: - -```php -$this->assertMethodExists(Post::class, 'save'); -``` - -#### `assertMethodNotExists()` - -Assert that object doesn't have the given method: - -```php -$this->assertMethodNotExists(Post::class, 'fly'); -``` - ### ScheduleAsserts #### `seeScheduleCount()` diff --git a/src/Asserts/ReflectionAsserts.php b/src/Asserts/ReflectionAsserts.php deleted file mode 100644 index 8705524..0000000 --- a/src/Asserts/ReflectionAsserts.php +++ /dev/null @@ -1,60 +0,0 @@ -assertTrue(is_subclass_of($class, $parent), $message); - } - - /** - * Assert that class is not a subclass of the given parent. - */ - protected function assertNotSubclassOf(string $class, string $parent): void - { - $message = "Failed asserting that class `{$class}` is not subclass of `{$parent}`."; - $this->assertFalse(is_subclass_of($class, $parent), $message); - } - - /** - * Assert that class uses the given trait. - */ - protected function assertTraitUsed(string $class, string $trait): void - { - $message = "Failed asserting that class `{$class}` is using trait `{$trait}`."; - $this->assertContains($trait, class_uses($class), $message); - } - - /** - * Assert that class doesn't use the given trait. - */ - protected function assertTraitNotUsed(string $class, string $trait): void - { - $message = "Failed asserting that class `{$class}` is not using trait `{$trait}`."; - $this->assertNotContains($trait, class_uses($class), $message); - } - - /** - * Assert that object has the given method. - */ - protected function assertMethodExists(object|string $object, string $method): void - { - $message = "Failed asserting that `{$method}` method exists on specified object."; - $this->assertTrue(method_exists($object, $method), $message); - } - - /** - * Assert that object doesn't have the given method. - */ - protected function assertMethodNotExists(object|string $object, string $method): void - { - $message = "Failed asserting that `{$method}` method not exists on specified object."; - $this->assertFalse(method_exists($object, $method), $message); - } -} diff --git a/src/TestingTools.php b/src/TestingTools.php index 8575941..3060f45 100644 --- a/src/TestingTools.php +++ b/src/TestingTools.php @@ -6,7 +6,6 @@ use Illuminated\Testing\Asserts\DatabaseAsserts; use Illuminated\Testing\Asserts\FilesystemAsserts; use Illuminated\Testing\Asserts\LogFileAsserts; -use Illuminated\Testing\Asserts\ReflectionAsserts; use Illuminated\Testing\Asserts\ScheduleAsserts; use Illuminated\Testing\Asserts\ServiceProviderAsserts; use Illuminated\Testing\Helpers\ApplicationHelpers; @@ -21,7 +20,6 @@ trait TestingTools use DatabaseAsserts; use FilesystemAsserts; use LogFileAsserts; - use ReflectionAsserts; use ScheduleAsserts; use ServiceProviderAsserts; } diff --git a/tests/Asserts/ReflectionAssertsTest.php b/tests/Asserts/ReflectionAssertsTest.php deleted file mode 100644 index b38ff7e..0000000 --- a/tests/Asserts/ReflectionAssertsTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertSubclassOf(Post::class, Model::class); - } - - /** @test */ - public function it_has_not_subclass_of_assertion() - { - $this->assertNotSubclassOf(Post::class, Command::class); - } - - /** @test */ - public function it_has_trait_used_assertion() - { - $this->assertTraitUsed(Post::class, Commentable::class); - } - - /** @test */ - public function it_has_trait_not_used_assertion() - { - $this->assertTraitNotUsed(Post::class, 'Acme\Trait\Fake'); - } - - /** @test */ - public function it_has_method_exists_assertion() - { - $this->assertMethodExists(Post::class, 'save'); - } - - /** @test */ - public function it_has_method_not_exists_assertion() - { - $this->assertMethodNotExists(Post::class, 'fake'); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2ae708b..affa95a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -78,4 +78,13 @@ protected function resolveApplicationConsoleKernel($app) app(KernelContract::class); } + + /** + * Assert that class uses the given trait. + */ + protected function assertTraitUsed(string $class, string $trait): void + { + $message = "Failed asserting that class `{$class}` is using trait `{$trait}`."; + $this->assertContains($trait, class_uses($class), $message); + } } diff --git a/tests/TestingToolsTest.php b/tests/TestingToolsTest.php index efbd665..a8ffba3 100644 --- a/tests/TestingToolsTest.php +++ b/tests/TestingToolsTest.php @@ -6,7 +6,6 @@ use Illuminated\Testing\Asserts\DatabaseAsserts; use Illuminated\Testing\Asserts\FilesystemAsserts; use Illuminated\Testing\Asserts\LogFileAsserts; -use Illuminated\Testing\Asserts\ReflectionAsserts; use Illuminated\Testing\Asserts\ScheduleAsserts; use Illuminated\Testing\Asserts\ServiceProviderAsserts; use Illuminated\Testing\Helpers\ApplicationHelpers; @@ -27,7 +26,6 @@ public function it_is_using_all_testing_tools_asserts() $this->assertTraitUsed(TestingTools::class, DatabaseAsserts::class); $this->assertTraitUsed(TestingTools::class, FilesystemAsserts::class); $this->assertTraitUsed(TestingTools::class, LogFileAsserts::class); - $this->assertTraitUsed(TestingTools::class, ReflectionAsserts::class); $this->assertTraitUsed(TestingTools::class, ScheduleAsserts::class); $this->assertTraitUsed(TestingTools::class, ServiceProviderAsserts::class); } diff --git a/tests/fixture/app/Commentable.php b/tests/fixture/app/Commentable.php deleted file mode 100644 index 746a567..0000000 --- a/tests/fixture/app/Commentable.php +++ /dev/null @@ -1,11 +0,0 @@ - $this->faker->sentence, - 'publish_at' => $this->faker->dateTimeThisYear, ]; } } diff --git a/tests/fixture/database/migrations/2016_11_01_131415_create_posts_table.php b/tests/fixture/database/migrations/2016_11_01_131415_create_posts_table.php index 291c01c..25100b8 100644 --- a/tests/fixture/database/migrations/2016_11_01_131415_create_posts_table.php +++ b/tests/fixture/database/migrations/2016_11_01_131415_create_posts_table.php @@ -14,16 +14,7 @@ public function up(): void Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title'); - $table->dateTime('publish_at'); $table->timestamps(); }); } - - /** - * Rollback the migration. - */ - public function down(): void - { - Schema::drop('posts'); - } };