diff --git a/composer.json b/composer.json index c2d719c..6d18834 100644 --- a/composer.json +++ b/composer.json @@ -5,10 +5,10 @@ "license": "MIT", "require": { "php": ">=8.2", - "cakephp/cakephp": "^5.0.1" + "cakephp/cakephp": "^5.1" }, "require-dev": { - "phpunit/phpunit": "^10.1", + "phpunit/phpunit": "^10.3", "cakephp/migrations": "^4.0.0", "phpstan/phpstan": "^2.1", "dereuromark/composer-prefer-lowest": "^0.1.10", diff --git a/tests/Fixture/ContactUsFormSubmissionsFixture.php b/tests/Fixture/ContactUsFormSubmissionsFixture.php index 0d42546..24cf5ce 100644 --- a/tests/Fixture/ContactUsFormSubmissionsFixture.php +++ b/tests/Fixture/ContactUsFormSubmissionsFixture.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeContactUs\Test\Fixture; -use Cake\I18n\FrozenTime; use Cake\TestSuite\Fixture\TestFixture; use Cake\Utility\Text; @@ -12,8 +11,6 @@ use Cake\Utility\Text; */ class ContactUsFormSubmissionsFixture extends TestFixture { - public string $table = 'contact_us_form_submissions'; - /** * Init method * @@ -23,7 +20,7 @@ class ContactUsFormSubmissionsFixture extends TestFixture { $this->records = [ [ 'id' => Text::uuid(), - 'submitted_at' => new FrozenTime(), + 'submitted_at' => '2018-07-21 16:11:03', 'client_ip' => 'cli', 'first_name' => 'test', 'last_name' => 'test', diff --git a/tests/TestCase/Controller/Component/ContactUsComponentTest.php b/tests/TestCase/Controller/Component/ContactUsComponentTest.php index 2f8793b..7c78142 100644 --- a/tests/TestCase/Controller/Component/ContactUsComponentTest.php +++ b/tests/TestCase/Controller/Component/ContactUsComponentTest.php @@ -9,6 +9,7 @@ use Cake\Http\ServerRequest; use Cake\TestSuite\TestCase; use CakeContactUs\Controller\Component\ContactUsComponent; use CakeContactUs\Model\Entity\ContactUsFormSubmission; +use CakeContactUs\Test\Fixture\ContactUsFormSubmissionsFixture; /** * CakeContactUs\Controller\Component\ContactUsComponent Test Case @@ -25,7 +26,7 @@ class ContactUsComponentTest extends TestCase { * @var array */ protected array $fixtures = [ - 'plugin.CakeContactUs.ContactUsFormSubmissions', + ContactUsFormSubmissionsFixture::class, ]; /** diff --git a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php index 255e74b..d905fc8 100644 --- a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php +++ b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php @@ -11,6 +11,7 @@ use Cake\TestSuite\EmailTrait; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use CakeContactUs\CakeContactUsPlugin; +use CakeContactUs\Test\Fixture\ContactUsFormSubmissionsFixture; /** * CakeContactUs\Controller\ContactUsFormSubmissionsController Test Case @@ -31,7 +32,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { * @var array */ protected array $fixtures = [ - 'plugin.CakeContactUs.ContactUsFormSubmissions', + ContactUsFormSubmissionsFixture::class, ]; /** @@ -41,7 +42,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { */ protected function setUp(): void { parent::setUp(); - $this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions'); + $this->ContactUsFormSubmissions = $this->getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions'); EventManager::instance()->setEventList(new EventList()); } diff --git a/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php b/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php index 553566d..4e32f4d 100644 --- a/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php +++ b/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php @@ -34,8 +34,8 @@ class ContactUsFormSubmissionsTableTest extends TestCase { */ protected function setUp(): void { parent::setUp(); - $config = $this->getTableLocator()->exists('ContactUsFormSubmissions') ? [] : ['className' => ContactUsFormSubmissionsTable::class]; - $this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions', $config); + $config = $this->getTableLocator()->exists('CakeContactUs.ContactUsFormSubmissions') ? [] : ['className' => ContactUsFormSubmissionsTable::class]; + $this->ContactUsFormSubmissions = $this->getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions', $config); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fc0e90b..d9896be 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,6 +10,7 @@ use Cake\Datasource\ConnectionManager; use Cake\Mailer\Mailer; use Cake\Mailer\Transport\DebugTransport; use Cake\Mailer\TransportFactory; +use Cake\TestSuite\Fixture\SchemaLoader; use CakeContactUs\CakeContactUsPlugin; use Migrations\TestSuite\Migrator; use TestApp\Controller\AppController; @@ -155,7 +156,7 @@ ConnectionManager::setConfig('test', [ * and using \Migrations\TestSuite\Migrator to load schema. */ // Load a schema dump file. -//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test'); +(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test'); if (!defined('SECOND')) { define('SECOND', 1); define('MINUTE', 60); @@ -166,11 +167,11 @@ if (!defined('SECOND')) { define('YEAR', 31536000); } -$migrator = new Migrator(); -$migrator->runMany([ - // Run app migrations on test connection. - ['connection' => 'test'], - // Run plugin migrations on test connection. - ['plugin' => 'CakeContactUs'], - ['plugin' => 'Captcha'], -]); +//$migrator = new Migrator(); +//$migrator->runMany([ +// // Run app migrations on test connection. +// ['connection' => 'test'], +// // Run plugin migrations on test connection. +// ['plugin' => 'CakeContactUs'], +// ['plugin' => 'Captcha'], +//]); diff --git a/tests/schema.php b/tests/schema.php new file mode 100644 index 0000000..72c3d84 --- /dev/null +++ b/tests/schema.php @@ -0,0 +1,44 @@ + $iterator + */ +$iterator = new DirectoryIterator(__DIR__ . DS . 'Fixture'); +foreach ($iterator as $file) { + if (!preg_match('/(\w+)Fixture.php$/', (string)$file, $matches)) { + continue; + } + + $name = $matches[1]; + $tableName = Inflector::underscore($name); + $class = 'CakeContactUs\\Test\\Fixture\\' . $name . 'Fixture'; + try { + $object = (new ReflectionClass($class))->getProperty('fields'); + } catch (ReflectionException $e) { + continue; + } + + $array = $object->getDefaultValue(); + $constraints = $array['_constraints'] ?? []; + $indexes = $array['_indexes'] ?? []; + unset($array['_constraints'], $array['_indexes'], $array['_options']); + $table = [ + 'table' => $tableName, + 'columns' => $array, + 'constraints' => $constraints, + 'indexes' => $indexes, + ]; + $tables[$tableName] = $table; +} + +return $tables; diff --git a/tests/schema.sql b/tests/schema.sql index ec83b63..9e644eb 100644 --- a/tests/schema.sql +++ b/tests/schema.sql @@ -1 +1,15 @@ -- Test database schema for CakeContactUs +CREATE TABLE `contact_us_form_submissions` +( + `id` char(36) NOT NULL, + `submitted_at` datetime NOT NULL, + `client_ip` varchar(45) DEFAULT NULL, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + `email` varchar(255) DEFAULT NULL, + `contact_subject` varchar(255) DEFAULT NULL, + `message` text NOT NULL, + `confirm_email_sent` datetime DEFAULT NULL, + `backend_email_sent` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +);