|
| 1 | +<?php |
| 2 | + |
| 3 | +use Codeception\Util\Autoload; |
| 4 | +use Codeception\Module\Phalcon4; |
| 5 | +use Codeception\Exception\ModuleConfigException; |
| 6 | + |
| 7 | +class Phalcon4ModuleTest extends \Codeception\Test\Unit |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @var \UnitTester |
| 11 | + */ |
| 12 | + protected $tester; |
| 13 | + |
| 14 | + protected function _setUp() |
| 15 | + { |
| 16 | + Autoload::addNamespace('Codeception\Module', BASE_PATH . '/src/Codeception/Module'); |
| 17 | + Autoload::addNamespace('Codeception\Lib\Connector\Phalcon4', BASE_PATH . '/src/Codeception/Lib/Connector/Phalcon4'); |
| 18 | + require_once BASE_PATH . '/src/Codeception/Lib/Connector/Phalcon4.php'; |
| 19 | + require_once BASE_PATH . '/src/Codeception/Lib/Connector/Phalcon4/MemorySession.php'; |
| 20 | + } |
| 21 | + |
| 22 | + protected function _before() |
| 23 | + { |
| 24 | + |
| 25 | + } |
| 26 | + |
| 27 | + protected function _after() |
| 28 | + { |
| 29 | + } |
| 30 | + |
| 31 | + protected function getPhalconModule() |
| 32 | + { |
| 33 | + $container = \Codeception\Util\Stub::make('Codeception\Lib\ModuleContainer'); |
| 34 | + $module = new Phalcon4($container); |
| 35 | + $module->_setConfig([ |
| 36 | + 'bootstrap' => 'tests/_data/bootstrap.php', |
| 37 | + 'cleanup' => true, |
| 38 | + 'savepoints' => true, |
| 39 | + 'session' => 'Codeception\Lib\Connector\Phalcon4\MemorySession' |
| 40 | + ]); |
| 41 | + $module->_initialize(); |
| 42 | + return $module; |
| 43 | + } |
| 44 | + |
| 45 | + protected function getPhalconModuleMicro() |
| 46 | + { |
| 47 | + $container = \Codeception\Util\Stub::make('Codeception\Lib\ModuleContainer'); |
| 48 | + $module = new Phalcon4($container); |
| 49 | + $module->_setConfig([ |
| 50 | + 'bootstrap' => 'tests/_data/bootstrap-micro.php', |
| 51 | + 'cleanup' => true, |
| 52 | + 'savepoints' => true, |
| 53 | + 'session' => PhalconConnector\MemorySession::class |
| 54 | + ]); |
| 55 | + $module->_initialize(); |
| 56 | + return $module; |
| 57 | + } |
| 58 | + |
| 59 | + public function testConstruct() |
| 60 | + { |
| 61 | + $container = \Codeception\Util\Stub::make('Codeception\Lib\ModuleContainer'); |
| 62 | + $module = new Phalcon4($container); |
| 63 | + $this->assertInstanceOf('Codeception\Module\Phalcon4', $module); |
| 64 | + } |
| 65 | + |
| 66 | + public function testInitialize() |
| 67 | + { |
| 68 | + $module = $this->getPhalconModule(); |
| 69 | + $this->assertInstanceOf('Codeception\Lib\Connector\Phalcon4', $module->client); |
| 70 | + } |
| 71 | + |
| 72 | + public function testBefore() |
| 73 | + { |
| 74 | + $module = $this->getPhalconModule(); |
| 75 | + $test = new Codeception\Test\Unit(); |
| 76 | + $module->_before($test); |
| 77 | + $this->assertInstanceOf('Phalcon\Di', $module->di); |
| 78 | + $this->assertInstanceOf('Phalcon\Di', $module->di); |
| 79 | + } |
| 80 | + |
| 81 | + public function testAfter() |
| 82 | + { |
| 83 | + $module = $this->getPhalconModule(); |
| 84 | + $test = new Codeception\Test\Unit(); |
| 85 | + $module->_before($test); |
| 86 | + $module->_after($test); |
| 87 | + $this->assertNull($module->di); |
| 88 | + } |
| 89 | + |
| 90 | + public function testParts() |
| 91 | + { |
| 92 | + $module = $this->getPhalconModule(); |
| 93 | + $this->assertEquals(['orm', 'services'], $module->_parts()); |
| 94 | + } |
| 95 | + |
| 96 | + public function testGetApplication() |
| 97 | + { |
| 98 | + $module = $this->getPhalconModule(); |
| 99 | + $test = new Codeception\Test\Unit(); |
| 100 | + $module->_before($test); |
| 101 | + $this->assertInstanceOf('Phalcon\Mvc\Application', $module->getApplication()); |
| 102 | + |
| 103 | + $module = $this->getPhalconModuleMicro(); |
| 104 | + $test = new Codeception\Test\Unit(); |
| 105 | + $module->_before($test); |
| 106 | + $this->assertInstanceOf('Phalcon\Mvc\Micro', $module->getApplication()); |
| 107 | + } |
| 108 | + |
| 109 | + public function testSession() |
| 110 | + { |
| 111 | + $module = $this->getPhalconModule(); |
| 112 | + $test = new Codeception\Test\Unit(); |
| 113 | + $module->_before($test); |
| 114 | + $key = "phalcon"; |
| 115 | + $value = "Rocks!"; |
| 116 | + $module->haveInSession($key, $value); |
| 117 | + $module->seeInSession($key, $value ); |
| 118 | + $module->seeSessionHasValues([$key => $value]); |
| 119 | + } |
| 120 | + |
| 121 | + public function testRecords() |
| 122 | + { |
| 123 | + require_once codecept_data_dir('models/test.php'); |
| 124 | + |
| 125 | + $module = $this->getPhalconModule(); |
| 126 | + $test = new Codeception\Test\Unit(); |
| 127 | + $module->_before($test); |
| 128 | + |
| 129 | + $module->haveRecord('Test', ['name' => 'phalcon']); |
| 130 | + $module->seeRecord('Test', ['name' => 'phalcon']); |
| 131 | + $module->seeNumberOfRecords('Test', 1); |
| 132 | + $module->haveRecord('Test', ['name' => 'phalcon']); |
| 133 | + $module->seeNumberOfRecords('Test', 2); |
| 134 | + $module->dontSeeRecord('Test', ['name' => 'wordpress']); |
| 135 | + |
| 136 | + $record = $module->grabRecord('Test', ['name' => 'phalcon']); |
| 137 | + $this->assertInstanceOf('Phalcon\Mvc\Model', $record); |
| 138 | + } |
| 139 | + |
| 140 | + public function testContainerMethods() |
| 141 | + { |
| 142 | + $module = $this->getPhalconModule(); |
| 143 | + $test = new Codeception\Test\Unit(); |
| 144 | + $module->_before($test); |
| 145 | + |
| 146 | + $session = $module->grabServiceFromContainer('session'); |
| 147 | + $this->assertInstanceOf('session', $session); |
| 148 | + } |
| 149 | +} |
0 commit comments