From 1d7a708fe434be30915cdff8d35805acb871370f Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 28 Mar 2024 18:53:02 +0530 Subject: [PATCH] Fix tests --- phpunit.xml.dist | 2 +- tests/Fixture/BlogsFixture.php | 11 +---------- .../TestCase/Listener/ViewSearchListenerTest.php | 10 ++++++---- tests/schema.php | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 tests/schema.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f6a7ea0..af94e92 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ - + diff --git a/tests/Fixture/BlogsFixture.php b/tests/Fixture/BlogsFixture.php index fa6da5e..8ac126f 100644 --- a/tests/Fixture/BlogsFixture.php +++ b/tests/Fixture/BlogsFixture.php @@ -7,16 +7,7 @@ class BlogsFixture extends TestFixture { - public $fields = [ - 'id' => ['type' => 'integer'], - 'is_active' => ['type' => 'boolean', 'default' => true, 'null' => false], - 'name' => ['type' => 'string', 'length' => 255, 'null' => false], - 'body' => ['type' => 'text', 'null' => false], - 'user_id' => ['type' => 'integer'], - '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], - ]; - - public $records = [ + public array $records = [ ['name' => '1st post', 'body' => '1st post body', 'user_id' => 1], ['name' => '2nd post', 'body' => '2nd post body', 'user_id' => 1], ['name' => '3rd post', 'body' => '3rd post body', 'user_id' => 1], diff --git a/tests/TestCase/Listener/ViewSearchListenerTest.php b/tests/TestCase/Listener/ViewSearchListenerTest.php index 8b3c905..e17d2ac 100644 --- a/tests/TestCase/Listener/ViewSearchListenerTest.php +++ b/tests/TestCase/Listener/ViewSearchListenerTest.php @@ -15,17 +15,17 @@ */ class ViewSearchListenerTest extends TestCase { - protected $fixtures = ['plugin.CrudView.Blogs']; + protected array $fixtures = ['plugin.CrudView.Blogs']; /** * @var \Cake\Controller\Controller; */ - protected $controller; + protected Controller $controller; /** * @var \CrudView\Listener\ViewSearchListener */ - protected $listener; + protected ViewSearchListener $listener; public function setUp(): void { @@ -39,7 +39,8 @@ public function setUp(): void 'params' => ['controller' => 'Blogs', 'action' => 'index', 'plugin' => null, '_ext' => null], ]); - $this->controller = new Controller($request, null, 'Blogs'); + $this->controller = new Controller($request, 'Blogs'); + $this->controller->loadComponent('Crud.Crud'); $this->listener = new ViewSearchListener($this->controller); @@ -67,6 +68,7 @@ public function testFields() 'data-tags' => 'true', 'data-allow-clear' => 'true', 'data-placeholder' => '', + 'empty' => 'Name', ], 'is_active' => [ 'required' => false, diff --git a/tests/schema.php b/tests/schema.php new file mode 100644 index 0000000..9715345 --- /dev/null +++ b/tests/schema.php @@ -0,0 +1,16 @@ + 'blogs', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'is_active' => ['type' => 'boolean', 'default' => true, 'null' => false], + 'name' => ['type' => 'string', 'length' => 255, 'null' => false], + 'body' => ['type' => 'text', 'null' => false], + 'user_id' => ['type' => 'integer'], + ], + 'constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], + ], +];