From 047311c4817e205d37965ba62d3c4613cac957df Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 21 Apr 2016 13:46:38 +0600 Subject: [PATCH] Code style fixes --- src/PHPCI/Model/Base/ProjectBase.php | 232 ++-- src/PHPCI/Model/Base/ProjectGroupBase.php | 53 +- src/PHPCI/Model/Base/UserBase.php | 99 +- tests/B8Framework/CodeGenerationTest.php | 1050 ++++++++--------- .../data/generation/models/BadModel.php | 15 +- .../data/generation/models/Dos.php | 28 +- .../data/generation/models/Tres.php | 42 +- .../data/generation/models/Uno.php | 35 +- .../data/generation/update_models/Dos.php | 28 +- .../data/generation/update_models/Tres.php | 58 +- .../data/generation/update_models/Uno.php | 33 +- .../PHPCI/Command/CreateAdminCommandTest.php | 12 +- .../PHPCI/Command/CreateBuildCommandTest.php | 26 +- tests/PHPCI/Command/InstallCommandTest.php | 40 +- tests/PHPCI/Helper/CommandExecutorTest.php | 10 +- tests/PHPCI/Helper/MailerFactoryTest.php | 32 +- tests/PHPCI/Logging/LoggerConfigTest.php | 20 +- tests/PHPCI/Model/BuildTest.php | 4 +- tests/PHPCI/Model/ProjectTest.php | 4 +- tests/PHPCI/Plugin/EmailTest.php | 98 +- tests/PHPCI/Plugin/PharTest.php | 18 +- .../PHPCI/Plugin/Util/ExamplePluginConfig.php | 4 +- tests/PHPCI/Plugin/Util/ExecutorTest.php | 10 +- tests/PHPCI/Plugin/Util/FactoryTest.php | 8 +- tests/PHPCI/Service/BuildServiceTest.php | 4 +- 25 files changed, 946 insertions(+), 1017 deletions(-) diff --git a/src/PHPCI/Model/Base/ProjectBase.php b/src/PHPCI/Model/Base/ProjectBase.php index 1e1821d7..6930c6bd 100644 --- a/src/PHPCI/Model/Base/ProjectBase.php +++ b/src/PHPCI/Model/Base/ProjectBase.php @@ -32,163 +32,161 @@ class ProjectBase extends Model /** * @var array */ - protected $data = array( - 'id' => null, - 'title' => null, - 'reference' => null, - 'branch' => null, - 'ssh_private_key' => null, - 'type' => null, - 'access_information' => null, - 'last_commit' => null, - 'build_config' => null, - 'ssh_public_key' => null, + protected $data = [ + 'id' => null, + 'title' => null, + 'reference' => null, + 'branch' => null, + 'ssh_private_key' => null, + 'type' => null, + 'access_information' => null, + 'last_commit' => null, + 'build_config' => null, + 'ssh_public_key' => null, 'allow_public_status' => null, - 'archived' => null, - 'group_id' => null, - ); + 'archived' => null, + 'group_id' => null, + ]; /** * @var array */ - protected $getters = array( + protected $getters = [ // Direct property getters: - 'id' => 'getId', - 'title' => 'getTitle', - 'reference' => 'getReference', - 'branch' => 'getBranch', - 'ssh_private_key' => 'getSshPrivateKey', - 'type' => 'getType', - 'access_information' => 'getAccessInformation', - 'last_commit' => 'getLastCommit', - 'build_config' => 'getBuildConfig', - 'ssh_public_key' => 'getSshPublicKey', + 'id' => 'getId', + 'title' => 'getTitle', + 'reference' => 'getReference', + 'branch' => 'getBranch', + 'ssh_private_key' => 'getSshPrivateKey', + 'type' => 'getType', + 'access_information' => 'getAccessInformation', + 'last_commit' => 'getLastCommit', + 'build_config' => 'getBuildConfig', + 'ssh_public_key' => 'getSshPublicKey', 'allow_public_status' => 'getAllowPublicStatus', - 'archived' => 'getArchived', - 'group_id' => 'getGroupId', - + 'archived' => 'getArchived', + 'group_id' => 'getGroupId', // Foreign key getters: - 'Group' => 'getGroup', - ); + 'Group' => 'getGroup', + ]; /** * @var array */ - protected $setters = array( + protected $setters = [ // Direct property setters: - 'id' => 'setId', - 'title' => 'setTitle', - 'reference' => 'setReference', - 'branch' => 'setBranch', - 'ssh_private_key' => 'setSshPrivateKey', - 'type' => 'setType', - 'access_information' => 'setAccessInformation', - 'last_commit' => 'setLastCommit', - 'build_config' => 'setBuildConfig', - 'ssh_public_key' => 'setSshPublicKey', + 'id' => 'setId', + 'title' => 'setTitle', + 'reference' => 'setReference', + 'branch' => 'setBranch', + 'ssh_private_key' => 'setSshPrivateKey', + 'type' => 'setType', + 'access_information' => 'setAccessInformation', + 'last_commit' => 'setLastCommit', + 'build_config' => 'setBuildConfig', + 'ssh_public_key' => 'setSshPublicKey', 'allow_public_status' => 'setAllowPublicStatus', - 'archived' => 'setArchived', - 'group_id' => 'setGroupId', - + 'archived' => 'setArchived', + 'group_id' => 'setGroupId', // Foreign key setters: - 'Group' => 'setGroup', - ); + 'Group' => 'setGroup', + ]; /** * @var array */ - public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, + public $columns = [ + 'id' => [ + 'type' => 'int', + 'length' => 11, + 'primary_key' => true, 'auto_increment' => true, + 'default' => null, + ], + 'title' => [ + 'type' => 'varchar', + 'length' => 250, 'default' => null, - ), - 'title' => array( - 'type' => 'varchar', - 'length' => 250, + ], + 'reference' => [ + 'type' => 'varchar', + 'length' => 250, 'default' => null, - ), - 'reference' => array( - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ), - 'branch' => array( - 'type' => 'varchar', - 'length' => 50, + ], + 'branch' => [ + 'type' => 'varchar', + 'length' => 50, 'default' => 'master', - ), - 'ssh_private_key' => array( - 'type' => 'text', + ], + 'ssh_private_key' => [ + 'type' => 'text', 'nullable' => true, + 'default' => null, + ], + 'type' => [ + 'type' => 'varchar', + 'length' => 50, 'default' => null, - ), - 'type' => array( - 'type' => 'varchar', - 'length' => 50, - 'default' => null, - ), - 'access_information' => array( - 'type' => 'varchar', - 'length' => 250, + ], + 'access_information' => [ + 'type' => 'varchar', + 'length' => 250, 'nullable' => true, - 'default' => null, - ), - 'last_commit' => array( - 'type' => 'varchar', - 'length' => 250, + 'default' => null, + ], + 'last_commit' => [ + 'type' => 'varchar', + 'length' => 250, 'nullable' => true, - 'default' => null, - ), - 'build_config' => array( - 'type' => 'text', + 'default' => null, + ], + 'build_config' => [ + 'type' => 'text', 'nullable' => true, - 'default' => null, - ), - 'ssh_public_key' => array( - 'type' => 'text', + 'default' => null, + ], + 'ssh_public_key' => [ + 'type' => 'text', 'nullable' => true, - 'default' => null, - ), - 'allow_public_status' => array( - 'type' => 'int', + 'default' => null, + ], + 'allow_public_status' => [ + 'type' => 'int', 'length' => 11, - ), - 'archived' => array( - 'type' => 'tinyint', - 'length' => 1, + ], + 'archived' => [ + 'type' => 'tinyint', + 'length' => 1, 'default' => null, - ), - 'group_id' => array( - 'type' => 'int', - 'length' => 11, + ], + 'group_id' => [ + 'type' => 'int', + 'length' => 11, 'default' => 1, - ), - ); + ], + ]; /** * @var array */ - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'idx_project_title' => array('columns' => 'title'), - 'group_id' => array('columns' => 'group_id'), - ); + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'id'], + 'idx_project_title' => ['columns' => 'title'], + 'group_id' => ['columns' => 'group_id'], + ]; /** * @var array */ - public $foreignKeys = array( - 'project_ibfk_1' => array( - 'local_col' => 'group_id', - 'update' => 'CASCADE', - 'delete' => '', - 'table' => 'project_group', - 'col' => 'id' - ), - ); + public $foreignKeys = [ + 'project_ibfk_1' => [ + 'local_col' => 'group_id', + 'update' => 'CASCADE', + 'delete' => '', + 'table' => 'project_group', + 'col' => 'id' + ], + ]; /** * Get the value of Id / id. diff --git a/src/PHPCI/Model/Base/ProjectGroupBase.php b/src/PHPCI/Model/Base/ProjectGroupBase.php index dda73df2..83c80afb 100644 --- a/src/PHPCI/Model/Base/ProjectGroupBase.php +++ b/src/PHPCI/Model/Base/ProjectGroupBase.php @@ -32,63 +32,60 @@ class ProjectGroupBase extends Model /** * @var array */ - protected $data = array( - 'id' => null, + protected $data = [ + 'id' => null, 'title' => null, - ); + ]; /** * @var array */ - protected $getters = array( + protected $getters = [ // Direct property getters: - 'id' => 'getId', + 'id' => 'getId', 'title' => 'getTitle', - // Foreign key getters: - ); + ]; /** * @var array */ - protected $setters = array( + protected $setters = [ // Direct property setters: - 'id' => 'setId', + 'id' => 'setId', 'title' => 'setTitle', - // Foreign key setters: - ); + ]; /** * @var array */ - public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, + public $columns = [ + 'id' => [ + 'type' => 'int', + 'length' => 11, + 'primary_key' => true, 'auto_increment' => true, + 'default' => null, + ], + 'title' => [ + 'type' => 'varchar', + 'length' => 100, 'default' => null, - ), - 'title' => array( - 'type' => 'varchar', - 'length' => 100, - 'default' => null, - ), - ); + ], + ]; /** * @var array */ - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - ); + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'id'], + ]; /** * @var array */ - public $foreignKeys = array( - ); + public $foreignKeys = []; /** * Get the value of Id / id. diff --git a/src/PHPCI/Model/Base/UserBase.php b/src/PHPCI/Model/Base/UserBase.php index e483a3be..c520b53f 100644 --- a/src/PHPCI/Model/Base/UserBase.php +++ b/src/PHPCI/Model/Base/UserBase.php @@ -32,89 +32,86 @@ class UserBase extends Model /** * @var array */ - protected $data = array( - 'id' => null, - 'email' => null, - 'hash' => null, + protected $data = [ + 'id' => null, + 'email' => null, + 'hash' => null, 'is_admin' => null, - 'name' => null, - ); + 'name' => null, + ]; /** * @var array */ - protected $getters = array( + protected $getters = [ // Direct property getters: - 'id' => 'getId', - 'email' => 'getEmail', - 'hash' => 'getHash', + 'id' => 'getId', + 'email' => 'getEmail', + 'hash' => 'getHash', 'is_admin' => 'getIsAdmin', - 'name' => 'getName', - + 'name' => 'getName', // Foreign key getters: - ); + ]; /** * @var array */ - protected $setters = array( + protected $setters = [ // Direct property setters: - 'id' => 'setId', - 'email' => 'setEmail', - 'hash' => 'setHash', + 'id' => 'setId', + 'email' => 'setEmail', + 'hash' => 'setHash', 'is_admin' => 'setIsAdmin', - 'name' => 'setName', - + 'name' => 'setName', // Foreign key setters: - ); + ]; /** * @var array */ - public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, + public $columns = [ + 'id' => [ + 'type' => 'int', + 'length' => 11, + 'primary_key' => true, 'auto_increment' => true, + 'default' => null, + ], + 'email' => [ + 'type' => 'varchar', + 'length' => 250, 'default' => null, - ), - 'email' => array( - 'type' => 'varchar', - 'length' => 250, + ], + 'hash' => [ + 'type' => 'varchar', + 'length' => 250, 'default' => null, - ), - 'hash' => array( - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ), - 'is_admin' => array( - 'type' => 'int', + ], + 'is_admin' => [ + 'type' => 'int', 'length' => 11, - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 250, + ], + 'name' => [ + 'type' => 'varchar', + 'length' => 250, 'default' => null, - ), - ); + ], + ]; /** * @var array */ - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'idx_email' => array('unique' => true, 'columns' => 'email'), - 'email' => array('unique' => true, 'columns' => 'email'), - 'name' => array('columns' => 'name'), - ); + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'id'], + 'idx_email' => ['unique' => true, 'columns' => 'email'], + 'email' => ['unique' => true, 'columns' => 'email'], + 'name' => ['columns' => 'name'], + ]; /** * @var array */ - public $foreignKeys = array( - ); + public $foreignKeys = []; /** * Get the value of Id / id. diff --git a/tests/B8Framework/CodeGenerationTest.php b/tests/B8Framework/CodeGenerationTest.php index 218662e6..e7822fe2 100644 --- a/tests/B8Framework/CodeGenerationTest.php +++ b/tests/B8Framework/CodeGenerationTest.php @@ -3,625 +3,571 @@ namespace Tests\b8; use b8\Database\Generator, - b8\Database\CodeGenerator, - b8\Database, - b8\Config; + b8\Database\CodeGenerator, + b8\Database, + b8\Config; class CodeGenerationTest extends \PHPUnit_Framework_TestCase { - protected static $_db; - protected static $_base; - - public static function setUpBeforeClass() - { - Database::setDetails('b8_test_' . getenv('PHPCI_BUILD'), 'b8_test', 'b8_test'); - Database::setWriteServers(array('localhost')); - Database::setReadServers(array('localhost')); - - $config = new Config(); - Config::getInstance()->set('b8.app.namespace', 'Generation'); - - self::$_db = Database::getConnection('write'); - - self::$_db->query('DROP TABLE IF EXISTS tres'); - self::$_db->query('DROP TABLE IF EXISTS dos'); - self::$_db->query('DROP TABLE IF EXISTS uno'); - - self::$_base = dirname(__FILE__) . '/data/generation/'; - $gen = new Generator(self::$_db, 'Test', self::$_base .'models/'); - $gen->generate(); - } - - public static function tearDownAfterClass() - { - self::$_db->query('DROP TABLE IF EXISTS tres'); - self::$_db->query('DROP TABLE IF EXISTS dos'); - self::$_db->query('DROP TABLE IF EXISTS uno'); - - unlink(self::$_base . 'Generation/Model/Base/UnoBase.php'); - unlink(self::$_base . 'Generation/Model/Base/DosBase.php'); - unlink(self::$_base . 'Generation/Model/Base/TresBase.php'); - unlink(self::$_base . 'Generation/Store/Base/UnoStoreBase.php'); - unlink(self::$_base . 'Generation/Store/Base/DosStoreBase.php'); - unlink(self::$_base . 'Generation/Store/Base/TresStoreBase.php'); - unlink(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'); - unlink(self::$_base . 'Generation/Controller/Base/DosControllerBase.php'); - unlink(self::$_base . 'Generation/Controller/Base/TresControllerBase.php'); - unlink(self::$_base . 'Generation/Model/Uno.php'); - unlink(self::$_base . 'Generation/Model/Dos.php'); - unlink(self::$_base . 'Generation/Model/Tres.php'); - unlink(self::$_base . 'Generation/Store/UnoStore.php'); - unlink(self::$_base . 'Generation/Store/DosStore.php'); - unlink(self::$_base . 'Generation/Store/TresStore.php'); - unlink(self::$_base . 'Generation/Controller/UnoController.php'); - unlink(self::$_base . 'Generation/Controller/DosController.php'); - unlink(self::$_base . 'Generation/Controller/TresController.php'); - } - - public function testGenerate() - { - error_reporting(E_ALL); - $codeGenerator = new CodeGenerator(self::$_db, 'Generation', self::$_base . 'Generation/'); - $codeGenerator->generateModels(); - $codeGenerator->generateStores(); - $codeGenerator->generateControllers(); - - $this->assertFileExists(self::$_base . 'Generation/Model/Base/UnoBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Model/Base/DosBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Model/Base/TresBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Store/Base/UnoStoreBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Store/Base/DosStoreBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Store/Base/TresStoreBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Controller/Base/DosControllerBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Controller/Base/TresControllerBase.php'); - $this->assertFileExists(self::$_base . 'Generation/Model/Uno.php'); - $this->assertFileExists(self::$_base . 'Generation/Model/Dos.php'); - $this->assertFileExists(self::$_base . 'Generation/Model/Tres.php'); - $this->assertFileExists(self::$_base . 'Generation/Store/UnoStore.php'); - $this->assertFileExists(self::$_base . 'Generation/Store/DosStore.php'); - $this->assertFileExists(self::$_base . 'Generation/Store/TresStore.php'); - $this->assertFileExists(self::$_base . 'Generation/Controller/UnoController.php'); - $this->assertFileExists(self::$_base . 'Generation/Controller/DosController.php'); - $this->assertFileExists(self::$_base . 'Generation/Controller/TresController.php'); - } - - /** - * @depends testGenerate - */ - public function testGeneratedModels() - { - if(!defined('APPLICATION_PATH')) - { - define('APPLICATION_PATH', self::$_base); - } - - require_once(self::$_base . 'Generation/Model/Base/UnoBase.php'); - require_once(self::$_base . 'Generation/Model/Base/DosBase.php'); - require_once(self::$_base . 'Generation/Model/Base/TresBase.php'); - require_once(self::$_base . 'Generation/Model/Uno.php'); - require_once(self::$_base . 'Generation/Model/Dos.php'); - require_once(self::$_base . 'Generation/Model/Tres.php'); - require_once(self::$_base . 'ArrayPropertyModel.php'); - - $uno = new Generation\Model\Uno(); - $dos = new Generation\Model\Dos(); - $tres = new Generation\Model\Tres(); - - $this->assertTrue($uno instanceof b8\Model); - $this->assertTrue($dos instanceof b8\Model); - $this->assertTrue($tres instanceof b8\Model); - - $this->assertTrue($uno instanceof Generation\Model\Base\UnoBase); - $this->assertTrue($dos instanceof Generation\Model\Base\DosBase); - $this->assertTrue($tres instanceof Generation\Model\Base\TresBase); - - $this->assertTrue($uno->getTableName() == 'uno'); - $this->assertTrue($dos->getTableName() == 'dos'); - $this->assertTrue($tres->getTableName() == 'tres'); - - $uno->setId(1); - $uno->setFieldDatetime(new DateTime()); - $this->assertTrue($uno->getFieldDatetime() instanceof DateTime); - - $unoArray = $uno->toArray(); - $this->assertArrayHasKey('field_varchar', $unoArray); - $this->assertTrue($unoArray['field_datetime'] instanceof DateTime); - - Generation\Model\Uno::$sleepable = array('id', 'field_varchar'); - $unoArray = $uno->toArray(); - $this->assertArrayHasKey('field_varchar', $unoArray); - $this->assertFalse(array_key_exists('field_datetime', $unoArray)); - - $tres->setField($uno); - $this->assertTrue($tres->getFieldInt() == 1); - - $this->assertTrue(in_array('id', $uno->getModified())); - $this->assertTrue(is_array($uno->getDataArray())); - - $uno->setValues(array('field_int' => 100, 'field_bob' => 100)); - $this->assertFalse(in_array('field_bob', $uno->getModified())); - $this->assertTrue($uno->getFieldInt() === 100); - - $uno->setFieldInt(true); - $this->assertTrue($uno->getFieldInt() === 1); - - $caught = false; - - try - { - $uno->setFieldInt('invalid'); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - $uno->setFieldInt('500'); - $this->assertTrue($uno->getFieldInt() === 500); - - $caught = false; - - try - { - $uno->setFieldFloat('invalid'); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - $uno->setFieldFloat('4.12'); - $this->assertTrue($uno->getFieldFloat() === 4.12); - - - $uno->setFieldDatetime('2014-01-01'); - $this->assertTrue($uno->getFieldDatetime() instanceof DateTime); - - $caught = false; - - try - { - $uno->setFieldDatetime(2012); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - - $caught = false; - - try - { - $uno->setFieldInt(null); - } - catch(Exception $ex) - { - $caught = true; - } + protected static $_db; + protected static $_base; + + public static function setUpBeforeClass() + { + Database::setDetails('b8_test_' . getenv('PHPCI_BUILD'), 'b8_test', 'b8_test'); + Database::setWriteServers(['localhost']); + Database::setReadServers(['localhost']); + + $config = new Config(); + Config::getInstance()->set('b8.app.namespace', 'Generation'); + + self::$_db = Database::getConnection('write'); + + self::$_db->query('DROP TABLE IF EXISTS tres'); + self::$_db->query('DROP TABLE IF EXISTS dos'); + self::$_db->query('DROP TABLE IF EXISTS uno'); + + self::$_base = dirname(__FILE__) . '/data/generation/'; + $gen = new Generator(self::$_db, 'Test', self::$_base . 'models/'); + $gen->generate(); + } + + public static function tearDownAfterClass() + { + self::$_db->query('DROP TABLE IF EXISTS tres'); + self::$_db->query('DROP TABLE IF EXISTS dos'); + self::$_db->query('DROP TABLE IF EXISTS uno'); + + unlink(self::$_base . 'Generation/Model/Base/UnoBase.php'); + unlink(self::$_base . 'Generation/Model/Base/DosBase.php'); + unlink(self::$_base . 'Generation/Model/Base/TresBase.php'); + unlink(self::$_base . 'Generation/Store/Base/UnoStoreBase.php'); + unlink(self::$_base . 'Generation/Store/Base/DosStoreBase.php'); + unlink(self::$_base . 'Generation/Store/Base/TresStoreBase.php'); + unlink(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'); + unlink(self::$_base . 'Generation/Controller/Base/DosControllerBase.php'); + unlink(self::$_base . 'Generation/Controller/Base/TresControllerBase.php'); + unlink(self::$_base . 'Generation/Model/Uno.php'); + unlink(self::$_base . 'Generation/Model/Dos.php'); + unlink(self::$_base . 'Generation/Model/Tres.php'); + unlink(self::$_base . 'Generation/Store/UnoStore.php'); + unlink(self::$_base . 'Generation/Store/DosStore.php'); + unlink(self::$_base . 'Generation/Store/TresStore.php'); + unlink(self::$_base . 'Generation/Controller/UnoController.php'); + unlink(self::$_base . 'Generation/Controller/DosController.php'); + unlink(self::$_base . 'Generation/Controller/TresController.php'); + } + + public function testGenerate() + { + error_reporting(E_ALL); + $codeGenerator = new CodeGenerator(self::$_db, 'Generation', self::$_base . 'Generation/'); + $codeGenerator->generateModels(); + $codeGenerator->generateStores(); + $codeGenerator->generateControllers(); + + $this->assertFileExists(self::$_base . 'Generation/Model/Base/UnoBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Model/Base/DosBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Model/Base/TresBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Store/Base/UnoStoreBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Store/Base/DosStoreBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Store/Base/TresStoreBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Controller/Base/DosControllerBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Controller/Base/TresControllerBase.php'); + $this->assertFileExists(self::$_base . 'Generation/Model/Uno.php'); + $this->assertFileExists(self::$_base . 'Generation/Model/Dos.php'); + $this->assertFileExists(self::$_base . 'Generation/Model/Tres.php'); + $this->assertFileExists(self::$_base . 'Generation/Store/UnoStore.php'); + $this->assertFileExists(self::$_base . 'Generation/Store/DosStore.php'); + $this->assertFileExists(self::$_base . 'Generation/Store/TresStore.php'); + $this->assertFileExists(self::$_base . 'Generation/Controller/UnoController.php'); + $this->assertFileExists(self::$_base . 'Generation/Controller/DosController.php'); + $this->assertFileExists(self::$_base . 'Generation/Controller/TresController.php'); + } + + /** + * @depends testGenerate + */ + public function testGeneratedModels() + { + if (!defined('APPLICATION_PATH')) { + define('APPLICATION_PATH', self::$_base); + } + + require_once(self::$_base . 'Generation/Model/Base/UnoBase.php'); + require_once(self::$_base . 'Generation/Model/Base/DosBase.php'); + require_once(self::$_base . 'Generation/Model/Base/TresBase.php'); + require_once(self::$_base . 'Generation/Model/Uno.php'); + require_once(self::$_base . 'Generation/Model/Dos.php'); + require_once(self::$_base . 'Generation/Model/Tres.php'); + require_once(self::$_base . 'ArrayPropertyModel.php'); + + $uno = new Generation\Model\Uno(); + $dos = new Generation\Model\Dos(); + $tres = new Generation\Model\Tres(); + + $this->assertTrue($uno instanceof b8\Model); + $this->assertTrue($dos instanceof b8\Model); + $this->assertTrue($tres instanceof b8\Model); + + $this->assertTrue($uno instanceof Generation\Model\Base\UnoBase); + $this->assertTrue($dos instanceof Generation\Model\Base\DosBase); + $this->assertTrue($tres instanceof Generation\Model\Base\TresBase); + + $this->assertTrue($uno->getTableName() == 'uno'); + $this->assertTrue($dos->getTableName() == 'dos'); + $this->assertTrue($tres->getTableName() == 'tres'); + + $uno->setId(1); + $uno->setFieldDatetime(new DateTime()); + $this->assertTrue($uno->getFieldDatetime() instanceof DateTime); + + $unoArray = $uno->toArray(); + $this->assertArrayHasKey('field_varchar', $unoArray); + $this->assertTrue($unoArray['field_datetime'] instanceof DateTime); + + Generation\Model\Uno::$sleepable = ['id', 'field_varchar']; + $unoArray = $uno->toArray(); + $this->assertArrayHasKey('field_varchar', $unoArray); + $this->assertFalse(array_key_exists('field_datetime', $unoArray)); + + $tres->setField($uno); + $this->assertTrue($tres->getFieldInt() == 1); + + $this->assertTrue(in_array('id', $uno->getModified())); + $this->assertTrue(is_array($uno->getDataArray())); + + $uno->setValues(['field_int' => 100, 'field_bob' => 100]); + $this->assertFalse(in_array('field_bob', $uno->getModified())); + $this->assertTrue($uno->getFieldInt() === 100); + + $uno->setFieldInt(true); + $this->assertTrue($uno->getFieldInt() === 1); + + $caught = false; + + try { + $uno->setFieldInt('invalid'); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + $uno->setFieldInt('500'); + $this->assertTrue($uno->getFieldInt() === 500); + + $caught = false; + + try { + $uno->setFieldFloat('invalid'); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + $uno->setFieldFloat('4.12'); + $this->assertTrue($uno->getFieldFloat() === 4.12); - $this->assertTrue($caught); - $caught = false; + $uno->setFieldDatetime('2014-01-01'); + $this->assertTrue($uno->getFieldDatetime() instanceof DateTime); - try - { - $uno->setValues(array('field_int' => 'null')); - } - catch(Exception $ex) - { - $caught = true; - } + $caught = false; - $this->assertTrue($caught); + try { + $uno->setFieldDatetime(2012); + } catch (Exception $ex) { + $caught = true; + } - $uno->setValues(array('field_int' => 'true')); - $this->assertTrue($uno->getFieldInt() === 1); + $this->assertTrue($caught); - $uno->setValues(array('field_int' => 'false')); - $this->assertTrue($uno->getFieldInt() === 0); - $caught = false; + $caught = false; - try - { - $uno->setFieldVarchar(false); - } - catch(Exception $ex) - { - $caught = true; - } + try { + $uno->setFieldInt(null); + } catch (Exception $ex) { + $caught = true; + } - $this->assertTrue($caught); + $this->assertTrue($caught); - $caught = false; + $caught = false; - try - { - $uno->setFieldVarchar('Hi'); - } - catch(Exception $ex) - { - $caught = true; - } + try { + $uno->setValues(['field_int' => 'null']); + } catch (Exception $ex) { + $caught = true; + } - $this->assertFalse($caught); + $this->assertTrue($caught); - // Test toArray() with an array property: - $aModel = new Generation\ArrayPropertyModel(); - $array = $aModel->toArray(); + $uno->setValues(['field_int' => 'true']); + $this->assertTrue($uno->getFieldInt() === 1); - $this->assertArrayHasKey('array_property', $array); - $this->assertTrue(is_array($array['array_property'])); - $this->assertTrue(is_array($array['array_property']['three'])); - $this->assertTrue($array['array_property']['one'] == 'two'); - } + $uno->setValues(['field_int' => 'false']); + $this->assertTrue($uno->getFieldInt() === 0); - /** - * @depends testGeneratedModels - */ - public function testGeneratedStores() - { - require_once(self::$_base . 'Generation/Store/Base/UnoStoreBase.php'); - require_once(self::$_base . 'Generation/Store/Base/DosStoreBase.php'); - require_once(self::$_base . 'Generation/Store/Base/TresStoreBase.php'); - require_once(self::$_base . 'Generation/Store/UnoStore.php'); - require_once(self::$_base . 'Generation/Store/DosStore.php'); - require_once(self::$_base . 'Generation/Store/TresStore.php'); + $caught = false; - $uno = new Generation\Store\UnoStore(); - $dos = new Generation\Store\DosStore(); - $tres = new Generation\Store\TresStore(); + try { + $uno->setFieldVarchar(false); + } catch (Exception $ex) { + $caught = true; + } - $this->assertTrue($uno instanceof b8\Store); - $this->assertTrue($dos instanceof b8\Store); - $this->assertTrue($tres instanceof b8\Store); + $this->assertTrue($caught); - $this->assertTrue($uno instanceof Generation\Store\Base\UnoStoreBase); - $this->assertTrue($dos instanceof Generation\Store\Base\DosStoreBase); - $this->assertTrue($tres instanceof Generation\Store\Base\TresStoreBase); + $caught = false; - $tresModel = new Generation\Model\Tres(); - $tresModel->setFieldVarchar('Hi'); + try { + $uno->setFieldVarchar('Hi'); + } catch (Exception $ex) { + $caught = true; + } - $caught = false; + $this->assertFalse($caught); - try - { - $tres->save($tresModel); - } - catch(Exception $ex) - { - $caught = true; - } + // Test toArray() with an array property: + $aModel = new Generation\ArrayPropertyModel(); + $array = $aModel->toArray(); - $this->assertTrue($caught); + $this->assertArrayHasKey('array_property', $array); + $this->assertTrue(is_array($array['array_property'])); + $this->assertTrue(is_array($array['array_property']['three'])); + $this->assertTrue($array['array_property']['one'] == 'two'); + } + /** + * @depends testGeneratedModels + */ + public function testGeneratedStores() + { + require_once(self::$_base . 'Generation/Store/Base/UnoStoreBase.php'); + require_once(self::$_base . 'Generation/Store/Base/DosStoreBase.php'); + require_once(self::$_base . 'Generation/Store/Base/TresStoreBase.php'); + require_once(self::$_base . 'Generation/Store/UnoStore.php'); + require_once(self::$_base . 'Generation/Store/DosStore.php'); + require_once(self::$_base . 'Generation/Store/TresStore.php'); - $caught = false; + $uno = new Generation\Store\UnoStore(); + $dos = new Generation\Store\DosStore(); + $tres = new Generation\Store\TresStore(); - try - { - $uno->save($tresModel); - } - catch(Exception $ex) - { - $caught = true; - } + $this->assertTrue($uno instanceof b8\Store); + $this->assertTrue($dos instanceof b8\Store); + $this->assertTrue($tres instanceof b8\Store); - $this->assertTrue($caught); + $this->assertTrue($uno instanceof Generation\Store\Base\UnoStoreBase); + $this->assertTrue($dos instanceof Generation\Store\Base\DosStoreBase); + $this->assertTrue($tres instanceof Generation\Store\Base\TresStoreBase); + $tresModel = new Generation\Model\Tres(); + $tresModel->setFieldVarchar('Hi'); - $unoModel = new Generation\Model\Uno(); - $unoModel->setFieldVarchar('Hi'); + $caught = false; - $unoModel = $uno->save($unoModel); - $id = $unoModel->getId(); - $this->assertTrue(!empty($id)); - $this->assertTrue($unoModel->getFieldVarchar() == 'Hi'); + try { + $tres->save($tresModel); + } catch (Exception $ex) { + $caught = true; + } - $unoModel->setFieldVarchar('Ha'); - $unoModel = $uno->save($unoModel); - $this->assertTrue($id == $unoModel->getId()); - $this->assertTrue($unoModel->getFieldVarchar() == 'Ha'); + $this->assertTrue($caught); - $unoModel = $uno->save($unoModel); - $this->assertTrue($id == $unoModel->getId()); - $this->assertTrue($unoModel->getFieldVarchar() == 'Ha'); - $unoModel2 = $uno->getByPrimaryKey($id); - $this->assertTrue($unoModel2->getId() == $unoModel->getId()); + $caught = false; - $res = $uno->getWhere(array('field_varchar' => 'Ha')); - $this->assertTrue($res['count'] != 0); + try { + $uno->save($tresModel); + } catch (Exception $ex) { + $caught = true; + } - $res = $uno->getWhere(array('id' => array('operator' => 'between', 'value' => array(0, 100)))); - $this->assertTrue($res['count'] != 0); + $this->assertTrue($caught); - $res = $uno->getWhere(array('id' => array('operator' => 'IN', 'value' => array(1, 2, 3, 4)))); - $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(array('id' => array('operator' => '!=', 'value' => array('null', 100)))); - $this->assertTrue($res['count'] != 0); + $unoModel = new Generation\Model\Uno(); + $unoModel->setFieldVarchar('Hi'); - $res = $uno->getWhere(array('id' => array('operator' => '==', 'value' => array('null')))); - $this->assertTrue($res['count'] == 0); + $unoModel = $uno->save($unoModel); + $id = $unoModel->getId(); + $this->assertTrue(!empty($id)); + $this->assertTrue($unoModel->getFieldVarchar() == 'Hi'); - $res = $uno->getWhere(array('id' => array('operator' => '==', 'value' => 'null'))); - $this->assertTrue($res['count'] == 0); + $unoModel->setFieldVarchar('Ha'); + $unoModel = $uno->save($unoModel); + $this->assertTrue($id == $unoModel->getId()); + $this->assertTrue($unoModel->getFieldVarchar() == 'Ha'); - $res = $uno->getWhere(array('id' => array('operator' => '!=', 'value' => 'null'))); - $this->assertTrue($res['count'] != 0); + $unoModel = $uno->save($unoModel); + $this->assertTrue($id == $unoModel->getId()); + $this->assertTrue($unoModel->getFieldVarchar() == 'Ha'); - $res = $uno->getWhere(array('field_varchar' => array('operator' => 'like', 'value' => 'Ha'))); - $this->assertTrue($res['count'] != 0); + $unoModel2 = $uno->getByPrimaryKey($id); + $this->assertTrue($unoModel2->getId() == $unoModel->getId()); - $res = $uno->getWhere(array('field_varchar' => array('operator' => '!=', 'value' => 'Hi'))); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['field_varchar' => 'Ha']); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(array('field_varchar' => array('Ha', 'Hi'))); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['id' => ['operator' => 'between', 'value' => [0, 100]]]); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(array('id' => 1), 1, 0, array('dos' => array('alias' => 'd', 'on' => 'd.id = uno.id')), array('id' => 'ASC')); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['id' => ['operator' => 'IN', 'value' => [1, 2, 3, 4]]]); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(array('id' => 1), 1, 0, array('dos' => array('alias' => 'd', 'on' => 'd.id = uno.id')), 'rand'); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['id' => ['operator' => '!=', 'value' => ['null', 100]]]); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(array('id' => 1), 1, 10); - $this->assertTrue(count($res['items']) == 0 && $res['count'] == 1); + $res = $uno->getWhere(['id' => ['operator' => '==', 'value' => ['null']]]); + $this->assertTrue($res['count'] == 0); + $res = $uno->getWhere(['id' => ['operator' => '==', 'value' => 'null']]); + $this->assertTrue($res['count'] == 0); - $caught = false; + $res = $uno->getWhere(['id' => ['operator' => '!=', 'value' => 'null']]); + $this->assertTrue($res['count'] != 0); - try - { - $uno->getWhere(['invalid_column' => 1]); - } - catch(Exception $ex) - { - $caught = true; - } + $res = $uno->getWhere(['field_varchar' => ['operator' => 'like', 'value' => 'Ha']]); + $this->assertTrue($res['count'] != 0); - $this->assertTrue($caught); + $res = $uno->getWhere(['field_varchar' => ['operator' => '!=', 'value' => 'Hi']]); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(['id' => 1], 1, 0, [], 'rand', ['LEFT JOIN dos d ON d.id = uno.id']); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['field_varchar' => ['Ha', 'Hi']]); + $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['id' => 1], 1, 0, ['dos' => ['alias' => 'd', 'on' => 'd.id = uno.id']], ['id' => 'ASC']); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere(['id' => 1], 1, 0, [], 'rand', [], 'field_varchar'); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['id' => 1], 1, 0, ['dos' => ['alias' => 'd', 'on' => 'd.id = uno.id']], 'rand'); + $this->assertTrue($res['count'] != 0); - $res = $uno->getWhere([], 1, 0, [], 'rand', [], null, [['type' => 'AND', 'query' => 'id = 1', 'params' => []]]); - $this->assertTrue($res['count'] != 0); + $res = $uno->getWhere(['id' => 1], 1, 10); + $this->assertTrue(count($res['items']) == 0 && $res['count'] == 1); - $res = $uno->getWhere(['id' => 2], 1, 0, [], 'rand', [], null, [['type' => 'AND', 'query' => 'id = ?', 'params' => ['id']]]); - $this->assertTrue($res['count'] == 0); - $caught = false; + $caught = false; - try - { - $uno->getWhere(['' => 1]); - } - catch(Exception $ex) - { - $caught = true; - } + try { + $uno->getWhere(['invalid_column' => 1]); + } catch (Exception $ex) { + $caught = true; + } - $this->assertTrue($caught); + $this->assertTrue($caught); - // ---- - // Tests for Model::toArray() with relationships: - // ---- - $tresModel->setField($unoModel); - $array = $tresModel->toArray(); + $res = $uno->getWhere(['id' => 1], 1, 0, [], 'rand', ['LEFT JOIN dos d ON d.id = uno.id']); + $this->assertTrue($res['count'] != 0); - $this->assertTrue(array_key_exists('Field', $array)); - $this->assertTrue(array_key_exists('id', $array['Field'])); - $this->assertTrue($array['Field']['id'] == $unoModel->getId()); - // ---- - // Tests for Store::delete() - // ---- + $res = $uno->getWhere(['id' => 1], 1, 0, [], 'rand', [], 'field_varchar'); + $this->assertTrue($res['count'] != 0); - $caught = false; - try - { - $tres->delete($tresModel); - } - catch(Exception $ex) - { - $caught = true; - } + $res = $uno->getWhere([], 1, 0, [], 'rand', [], null, [['type' => 'AND', 'query' => 'id = 1', 'params' => []]]); + $this->assertTrue($res['count'] != 0); - $this->assertTrue($caught); + $res = $uno->getWhere(['id' => 2], 1, 0, [], 'rand', [], null, + [['type' => 'AND', 'query' => 'id = ?', 'params' => ['id']]]); + $this->assertTrue($res['count'] == 0); - $caught = false; - try - { - $uno->delete($tresModel); - } - catch(Exception $ex) - { - $caught = true; - } + $caught = false; - $this->assertTrue($caught); + try { + $uno->getWhere(['' => 1]); + } catch (Exception $ex) { + $caught = true; + } + $this->assertTrue($caught); - $this->assertTrue($uno->delete($unoModel)); - $this->assertTrue(is_null($uno->getByPrimaryKey(1))); - } - - /** - * @depends testGeneratedStores - */ - public function testGeneratedControllers() - { - require_once(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'); - require_once(self::$_base . 'Generation/Controller/Base/DosControllerBase.php'); - require_once(self::$_base . 'Generation/Controller/Base/TresControllerBase.php'); - require_once(self::$_base . 'Generation/Controller/UnoController.php'); - require_once(self::$_base . 'Generation/Controller/DosController.php'); - require_once(self::$_base . 'Generation/Controller/TresController.php'); - require_once(self::$_base . 'TestUser.php'); - - $uno = new Generation\Controller\UnoController(); - $dos = new Generation\Controller\DosController(); - $tres = new Generation\Controller\TresController(); - - $uno->init(); - $dos->init(); - $tres->init(); - - $this->assertTrue($uno instanceof b8\Controller); - $this->assertTrue($dos instanceof b8\Controller); - $this->assertTrue($tres instanceof b8\Controller); - - $this->assertTrue($uno instanceof Generation\Controller\Base\UnoControllerBase); - $this->assertTrue($dos instanceof Generation\Controller\Base\DosControllerBase); - $this->assertTrue($tres instanceof Generation\Controller\Base\TresControllerBase); - - $config = new Config(); - Config::getInstance()->set('hello', 'world'); - - $this->assertTrue($uno->getParam('hello', 'dave') == 'world'); - - $uno->setParam('hello', 'dave'); - $this->assertTrue($uno->getParam('hello', 'world') == 'dave'); - $this->assertTrue(array_key_exists('hello', $uno->getParams())); - - $uno->unsetParam('hello'); - $this->assertFalse(array_key_exists('hello', $uno->getParams())); - - $testUser = new \TestUser(); - $uno->setActiveUser($testUser); - $dos->setActiveUser($uno->getActiveUser()); - $tres->setActiveUser($uno->getActiveUser()); - - $unoModel = new Generation\Model\Uno(); - $unoStore = \b8\Store\Factory::getStore('Uno'); - $unoModel->setFieldVarchar('Hi'); - - $unoStore->save($unoModel); - $list = $uno->index(); - - $this->assertTrue(is_array($list)); - $this->assertTrue(is_array($list['items'])); - $this->assertTrue(count($list['items']) > 0); - - $caught = false; - try - { - $dos->index(); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - - $first = array_shift($list['items']); - - $uno1 = $uno->get($first['id']); - $this->assertTrue(is_array($uno1)); - $this->assertTrue(isset($uno1['uno'])); - $this->assertTrue($uno1['uno']['id'] == $first['id']); - - $caught = false; - try - { - $dos->get(1); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - - $uno->setParam('field_varchar', 'Un'); - $uno1 = $uno->put($first['id']); - $this->assertTrue($uno1['uno']['id'] == $first['id']); - - $caught = false; - try - { - $dos->put(1); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - $this->assertTrue(is_null($uno->put(10000))); - - - $uno->setParam('field_text', 'Hello'); - $res = $uno->post(); - $this->assertTrue($res['uno']['field_varchar'] == 'Un'); - $this->assertTrue(!empty($res['uno']['id'])); - - $caught = false; - try - { - $dos->post(); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - $del = $uno->delete($res['uno']['id']); - $this->assertTrue($del['deleted']); - - $del = $uno->delete($res['uno']['id']); - $this->assertFalse($del['deleted']); - - $del = $tres->delete(100); - $this->assertFalse($del['deleted']); - - $caught = false; - try - { - $dos->delete(1000); - } - catch(Exception $ex) - { - $caught = true; - } - - $this->assertTrue($caught); - - //---- - // Tests for _parseWhere() - //---- - $uno->setParam('where', ['id' => [1000]]); - $uno->setParam('neq', 'id'); - $list = $uno->index(); - - $this->assertTrue(is_array($list)); - $this->assertTrue(count($list['items']) != 0); - - $uno->setParam('where', ['id' => 1000]); - $uno->setParam('fuzzy', 'id'); - $list = $uno->index(); - - $this->assertTrue(is_array($list)); - $this->assertTrue(count($list['items']) == 0); - } + // ---- + // Tests for Model::toArray() with relationships: + // ---- + $tresModel->setField($unoModel); + $array = $tresModel->toArray(); + + $this->assertTrue(array_key_exists('Field', $array)); + $this->assertTrue(array_key_exists('id', $array['Field'])); + $this->assertTrue($array['Field']['id'] == $unoModel->getId()); + + // ---- + // Tests for Store::delete() + // ---- + + $caught = false; + try { + $tres->delete($tresModel); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + $caught = false; + try { + $uno->delete($tresModel); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + + $this->assertTrue($uno->delete($unoModel)); + $this->assertTrue(is_null($uno->getByPrimaryKey(1))); + } + + /** + * @depends testGeneratedStores + */ + public function testGeneratedControllers() + { + require_once(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'); + require_once(self::$_base . 'Generation/Controller/Base/DosControllerBase.php'); + require_once(self::$_base . 'Generation/Controller/Base/TresControllerBase.php'); + require_once(self::$_base . 'Generation/Controller/UnoController.php'); + require_once(self::$_base . 'Generation/Controller/DosController.php'); + require_once(self::$_base . 'Generation/Controller/TresController.php'); + require_once(self::$_base . 'TestUser.php'); + + $uno = new Generation\Controller\UnoController(); + $dos = new Generation\Controller\DosController(); + $tres = new Generation\Controller\TresController(); + + $uno->init(); + $dos->init(); + $tres->init(); + + $this->assertTrue($uno instanceof b8\Controller); + $this->assertTrue($dos instanceof b8\Controller); + $this->assertTrue($tres instanceof b8\Controller); + + $this->assertTrue($uno instanceof Generation\Controller\Base\UnoControllerBase); + $this->assertTrue($dos instanceof Generation\Controller\Base\DosControllerBase); + $this->assertTrue($tres instanceof Generation\Controller\Base\TresControllerBase); + + $config = new Config(); + Config::getInstance()->set('hello', 'world'); + + $this->assertTrue($uno->getParam('hello', 'dave') == 'world'); + + $uno->setParam('hello', 'dave'); + $this->assertTrue($uno->getParam('hello', 'world') == 'dave'); + $this->assertTrue(array_key_exists('hello', $uno->getParams())); + + $uno->unsetParam('hello'); + $this->assertFalse(array_key_exists('hello', $uno->getParams())); + + $testUser = new \TestUser(); + $uno->setActiveUser($testUser); + $dos->setActiveUser($uno->getActiveUser()); + $tres->setActiveUser($uno->getActiveUser()); + + $unoModel = new Generation\Model\Uno(); + $unoStore = \b8\Store\Factory::getStore('Uno'); + $unoModel->setFieldVarchar('Hi'); + + $unoStore->save($unoModel); + $list = $uno->index(); + + $this->assertTrue(is_array($list)); + $this->assertTrue(is_array($list['items'])); + $this->assertTrue(count($list['items']) > 0); + + $caught = false; + try { + $dos->index(); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + + $first = array_shift($list['items']); + + $uno1 = $uno->get($first['id']); + $this->assertTrue(is_array($uno1)); + $this->assertTrue(isset($uno1['uno'])); + $this->assertTrue($uno1['uno']['id'] == $first['id']); + + $caught = false; + try { + $dos->get(1); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + + $uno->setParam('field_varchar', 'Un'); + $uno1 = $uno->put($first['id']); + $this->assertTrue($uno1['uno']['id'] == $first['id']); + + $caught = false; + try { + $dos->put(1); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + $this->assertTrue(is_null($uno->put(10000))); + + + $uno->setParam('field_text', 'Hello'); + $res = $uno->post(); + $this->assertTrue($res['uno']['field_varchar'] == 'Un'); + $this->assertTrue(!empty($res['uno']['id'])); + + $caught = false; + try { + $dos->post(); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + $del = $uno->delete($res['uno']['id']); + $this->assertTrue($del['deleted']); + + $del = $uno->delete($res['uno']['id']); + $this->assertFalse($del['deleted']); + + $del = $tres->delete(100); + $this->assertFalse($del['deleted']); + + $caught = false; + try { + $dos->delete(1000); + } catch (Exception $ex) { + $caught = true; + } + + $this->assertTrue($caught); + + //---- + // Tests for _parseWhere() + //---- + $uno->setParam('where', ['id' => [1000]]); + $uno->setParam('neq', 'id'); + $list = $uno->index(); + + $this->assertTrue(is_array($list)); + $this->assertTrue(count($list['items']) != 0); + + $uno->setParam('where', ['id' => 1000]); + $uno->setParam('fuzzy', 'id'); + $list = $uno->index(); + + $this->assertTrue(is_array($list)); + $this->assertTrue(count($list['items']) == 0); + } } diff --git a/tests/B8Framework/data/generation/models/BadModel.php b/tests/B8Framework/data/generation/models/BadModel.php index cb1b77a3..140f400b 100755 --- a/tests/B8Framework/data/generation/models/BadModel.php +++ b/tests/B8Framework/data/generation/models/BadModel.php @@ -1,18 +1,17 @@ array('type' => 'catfish'), - ); + public $columns = [ + 'id' => ['type' => 'catfish'], + ]; - public $indexes = array( - ); - public $foreignKeys = array( - ); + public $indexes = []; + public $foreignKeys = []; } \ No newline at end of file diff --git a/tests/B8Framework/data/generation/models/Dos.php b/tests/B8Framework/data/generation/models/Dos.php index f3c3f4c0..20e31f96 100755 --- a/tests/B8Framework/data/generation/models/Dos.php +++ b/tests/B8Framework/data/generation/models/Dos.php @@ -1,24 +1,24 @@ array('type' => 'int', 'primary_key' => true, 'auto_increment' => false), - 'field_varchar' => array('type' => 'varchar', 'length' => '250', 'default' => 'Hello World'), - 'field_datetime'=> array('type' => 'datetime'), - 'field_int' => array('type' => 'int'), - ); + public $columns = [ + 'id' => ['type' => 'int', 'primary_key' => true, 'auto_increment' => false], + 'field_varchar' => ['type' => 'varchar', 'length' => '250', 'default' => 'Hello World'], + 'field_datetime' => ['type' => 'datetime'], + 'field_int' => ['type' => 'int'], + ]; - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'idx_test_1' => array('unique' => true, 'columns' => 'field_int'), - 'idx_test_2' => array('columns' => 'field_datetime'), - ); - public $foreignKeys = array( - ); + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'id'], + 'idx_test_1' => ['unique' => true, 'columns' => 'field_int'], + 'idx_test_2' => ['columns' => 'field_datetime'], + ]; + public $foreignKeys = []; } \ No newline at end of file diff --git a/tests/B8Framework/data/generation/models/Tres.php b/tests/B8Framework/data/generation/models/Tres.php index 4edee2ae..45bf5faf 100755 --- a/tests/B8Framework/data/generation/models/Tres.php +++ b/tests/B8Framework/data/generation/models/Tres.php @@ -1,27 +1,35 @@ array('type' => 'int'), - 'field_varchar' => array('type' => 'varchar', 'length' => '250'), - 'field_date' => array('type' => 'date'), - 'field_datetime'=> array('type' => 'datetime'), - 'field_int' => array('type' => 'int'), - 'field_int_2' => array('type' => 'int'), - ); + public $columns = [ + 'id' => ['type' => 'int'], + 'field_varchar' => ['type' => 'varchar', 'length' => '250'], + 'field_date' => ['type' => 'date'], + 'field_datetime' => ['type' => 'datetime'], + 'field_int' => ['type' => 'int'], + 'field_int_2' => ['type' => 'int'], + ]; - public $indexes = array( - 'fk_tres_uno' => array('columns' => 'field_int'), - 'fk_tres_dos' => array('columns' => 'field_int_2'), - ); - public $foreignKeys = array( - 'fk_tres_uno' => array('local_col' => 'field_int', 'table' => 'uno', 'col' => 'id'), - 'fk_tres_dos' => array('local_col' => 'field_int_2', 'update' => 'NO ACTION', 'delete' => 'CASCADE', 'table' => 'dos', 'col' => 'id'), - ); + public $indexes = [ + 'fk_tres_uno' => ['columns' => 'field_int'], + 'fk_tres_dos' => ['columns' => 'field_int_2'], + ]; + + public $foreignKeys = [ + 'fk_tres_uno' => ['local_col' => 'field_int', 'table' => 'uno', 'col' => 'id'], + 'fk_tres_dos' => [ + 'local_col' => 'field_int_2', + 'update' => 'NO ACTION', + 'delete' => 'CASCADE', + 'table' => 'dos', + 'col' => 'id' + ], + ]; } \ No newline at end of file diff --git a/tests/B8Framework/data/generation/models/Uno.php b/tests/B8Framework/data/generation/models/Uno.php index 0625ac97..01cc7540 100755 --- a/tests/B8Framework/data/generation/models/Uno.php +++ b/tests/B8Framework/data/generation/models/Uno.php @@ -1,28 +1,27 @@ array('type' => 'int', 'primary_key' => true, 'auto_increment' => true), - 'field_varchar' => array('type' => 'varchar', 'length' => '250'), - 'field_text' => array('type' => 'text'), - 'field_ltext' => array('type' => 'longtext'), - 'field_mtext' => array('type' => 'mediumtext'), - 'field_date' => array('type' => 'date'), - 'field_datetime'=> array('type' => 'datetime'), - 'field_int' => array('type' => 'int'), - 'field_tinyint' => array('type' => 'tinyint', 'length' => '1'), - 'field_float' => array('type' => 'float'), - 'field_double' => array('type' => 'double', 'length' => '15,2'), - ); + public $columns = [ + 'id' => ['type' => 'int', 'primary_key' => true, 'auto_increment' => true], + 'field_varchar' => ['type' => 'varchar', 'length' => '250'], + 'field_text' => ['type' => 'text'], + 'field_ltext' => ['type' => 'longtext'], + 'field_mtext' => ['type' => 'mediumtext'], + 'field_date' => ['type' => 'date'], + 'field_datetime' => ['type' => 'datetime'], + 'field_int' => ['type' => 'int'], + 'field_tinyint' => ['type' => 'tinyint', 'length' => '1'], + 'field_float' => ['type' => 'float'], + 'field_double' => ['type' => 'double', 'length' => '15,2'], + ]; - public $indexes = array( - ); - public $foreignKeys = array( - ); + public $indexes = []; + public $foreignKeys = []; } \ No newline at end of file diff --git a/tests/B8Framework/data/generation/update_models/Dos.php b/tests/B8Framework/data/generation/update_models/Dos.php index f82e333c..de58edd1 100755 --- a/tests/B8Framework/data/generation/update_models/Dos.php +++ b/tests/B8Framework/data/generation/update_models/Dos.php @@ -1,24 +1,24 @@ array('type' => 'int', 'primary_key' => true, 'auto_increment' => true), - 'field_varchar' => array('type' => 'varchar', 'length' => '250', 'default' => 'Hello World'), - 'field_datetime'=> array('type' => 'datetime'), - 'field_int' => array('type' => 'int'), - ); + public $columns = [ + 'id' => ['type' => 'int', 'primary_key' => true, 'auto_increment' => true], + 'field_varchar' => ['type' => 'varchar', 'length' => '250', 'default' => 'Hello World'], + 'field_datetime' => ['type' => 'datetime'], + 'field_int' => ['type' => 'int'], + ]; - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'idx_test_1' => array('unique' => false, 'columns' => 'field_int'), - 'idx_test_2' => array('columns' => 'field_datetime'), - ); - public $foreignKeys = array( - ); + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'id'], + 'idx_test_1' => ['unique' => false, 'columns' => 'field_int'], + 'idx_test_2' => ['columns' => 'field_datetime'], + ]; + public $foreignKeys = []; } \ No newline at end of file diff --git a/tests/B8Framework/data/generation/update_models/Tres.php b/tests/B8Framework/data/generation/update_models/Tres.php index 6d974063..fd1b4d11 100755 --- a/tests/B8Framework/data/generation/update_models/Tres.php +++ b/tests/B8Framework/data/generation/update_models/Tres.php @@ -1,32 +1,46 @@ array('type' => 'int', 'primary_key' => true, 'auto_increment' => true), - 'id' => array('type' => 'int'), - 'field_varchar' => array('type' => 'varchar', 'length' => '250', 'default' => 'Hello World'), - 'field_datetime'=> array('type' => 'datetime'), - 'field_int' => array('type' => 'int'), - 'field_int_2' => array('type' => 'int'), - 'field_dt' => array('type' => 'date', 'rename' => 'field_date'), - 'field_float_1' => array('type' => 'float', 'default' => '1'), - 'field_varchar_2' => array('type' => 'varchar', 'length' => '10', 'default' => 'Hello'), - 'dosid' => array('type' => 'int'), - ); + public $columns = [ + 'key_col' => ['type' => 'int', 'primary_key' => true, 'auto_increment' => true], + 'id' => ['type' => 'int'], + 'field_varchar' => ['type' => 'varchar', 'length' => '250', 'default' => 'Hello World'], + 'field_datetime' => ['type' => 'datetime'], + 'field_int' => ['type' => 'int'], + 'field_int_2' => ['type' => 'int'], + 'field_dt' => ['type' => 'date', 'rename' => 'field_date'], + 'field_float_1' => ['type' => 'float', 'default' => '1'], + 'field_varchar_2' => ['type' => 'varchar', 'length' => '10', 'default' => 'Hello'], + 'dosid' => ['type' => 'int'], + ]; - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'key_col'), - 'fk_tres_dos' => array('columns' => 'field_int_2'), - 'fk_tres_dos_2' => array('columns' => 'dosid'), - ); - public $foreignKeys = array( - 'fk_tres_dos' => array('local_col' => 'field_int_2', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'dos', 'col' => 'id'), - 'fk_tres_dos_2' => array('local_col' => 'dosid', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'dos', 'col' => 'id'), - ); + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'key_col'], + 'fk_tres_dos' => ['columns' => 'field_int_2'], + 'fk_tres_dos_2' => ['columns' => 'dosid'], + ]; + + public $foreignKeys = [ + 'fk_tres_dos' => [ + 'local_col' => 'field_int_2', + 'update' => 'CASCADE', + 'delete' => 'CASCADE', + 'table' => 'dos', + 'col' => 'id' + ], + 'fk_tres_dos_2' => [ + 'local_col' => 'dosid', + 'update' => 'CASCADE', + 'delete' => 'CASCADE', + 'table' => 'dos', + 'col' => 'id' + ], + ]; } \ No newline at end of file diff --git a/tests/B8Framework/data/generation/update_models/Uno.php b/tests/B8Framework/data/generation/update_models/Uno.php index cbe359cc..689e9a45 100755 --- a/tests/B8Framework/data/generation/update_models/Uno.php +++ b/tests/B8Framework/data/generation/update_models/Uno.php @@ -1,27 +1,26 @@ array('type' => 'int', 'primary_key' => true), - 'field_varchar' => array('type' => 'varchar', 'length' => '250'), - 'field_text' => array('type' => 'text'), - 'field_ltext' => array('type' => 'longtext'), - 'field_mtext' => array('type' => 'mediumtext'), - 'field_datetime'=> array('type' => 'datetime'), - 'field_int' => array('type' => 'int'), - 'field_tinyint' => array('type' => 'tinyint', 'length' => '1'), - 'field_float' => array('type' => 'float'), - 'field_double' => array('type' => 'double', 'length' => '15,2'), - ); + public $columns = [ + 'id' => ['type' => 'int', 'primary_key' => true], + 'field_varchar' => ['type' => 'varchar', 'length' => '250'], + 'field_text' => ['type' => 'text'], + 'field_ltext' => ['type' => 'longtext'], + 'field_mtext' => ['type' => 'mediumtext'], + 'field_datetime' => ['type' => 'datetime'], + 'field_int' => ['type' => 'int'], + 'field_tinyint' => ['type' => 'tinyint', 'length' => '1'], + 'field_float' => ['type' => 'float'], + 'field_double' => ['type' => 'double', 'length' => '15,2'], + ]; - public $indexes = array( - ); - public $foreignKeys = array( - ); + public $indexes = []; + public $foreignKeys = []; } \ No newline at end of file diff --git a/tests/PHPCI/Command/CreateAdminCommandTest.php b/tests/PHPCI/Command/CreateAdminCommandTest.php index 1e4eff8e..15ee0bf2 100644 --- a/tests/PHPCI/Command/CreateAdminCommandTest.php +++ b/tests/PHPCI/Command/CreateAdminCommandTest.php @@ -35,18 +35,16 @@ class CreateAdminCommandTest extends \PHPUnit_Framework_TestCase parent::setup(); $this->command = $this->getMockBuilder('PHPCI\\Command\\CreateAdminCommand') - ->setConstructorArgs(array($this->getMock('PHPCI\\Store\\UserStore'))) - ->setMethods(array('reloadConfig')) - ->getMock() - ; + ->setConstructorArgs([$this->getMock('PHPCI\\Store\\UserStore')]) + ->setMethods(['reloadConfig']) + ->getMock(); $this->dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper') - ->setMethods(array( + ->setMethods([ 'ask', 'askAndValidate', 'askHiddenResponse', - )) - ->getMock() + ])->getMock() ; $this->application = new Application(); diff --git a/tests/PHPCI/Command/CreateBuildCommandTest.php b/tests/PHPCI/Command/CreateBuildCommandTest.php index e82ae517..7311dd98 100644 --- a/tests/PHPCI/Command/CreateBuildCommandTest.php +++ b/tests/PHPCI/Command/CreateBuildCommandTest.php @@ -33,24 +33,24 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase $projectStoreMock = $this->getMockBuilder('PHPCI\\Store\\ProjectStore') ->getMock(); $projectStoreMock->method('getById') - ->will($this->returnValueMap(array( - array(1, 'read', $projectMock), - array(2, 'read', null), - ))); + ->will($this->returnValueMap([ + [1, 'read', $projectMock], + [2, 'read', null], + ])); $buildServiceMock = $this->getMockBuilder('PHPCI\\Service\\BuildService') ->disableOriginalConstructor() ->getMock(); $buildServiceMock->method('createBuild') ->withConsecutive( - array($projectMock, null, null, null, null, null), - array($projectMock, '92c8c6e', null, null, null, null), - array($projectMock, null, 'master', null, null, null) + [$projectMock, null, null, null, null, null], + [$projectMock, '92c8c6e', null, null, null, null], + [$projectMock, null, 'master', null, null, null] ); $this->command = $this->getMockBuilder('PHPCI\\Command\\CreateBuildCommand') - ->setConstructorArgs(array($projectStoreMock, $buildServiceMock)) - ->setMethods(array('reloadConfig')) + ->setConstructorArgs([$projectStoreMock, $buildServiceMock]) + ->setMethods(['reloadConfig']) ->getMock(); $this->application = new Application(); @@ -70,9 +70,9 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase { $commandTester = $this->getCommandTester(); - $commandTester->execute(array('projectId' => 1)); - $commandTester->execute(array('projectId' => 1, '--commit' => '92c8c6e')); - $commandTester->execute(array('projectId' => 1, '--branch' => 'master')); + $commandTester->execute(['projectId' => 1]); + $commandTester->execute(['projectId' => 1, '--commit' => '92c8c6e']); + $commandTester->execute(['projectId' => 1, '--branch' => 'master']); } /** @@ -81,6 +81,6 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase public function testExecuteWithUnknownProjectId() { $commandTester = $this->getCommandTester(); - $commandTester->execute(array('projectId' => 2)); + $commandTester->execute(['projectId' => 2]); } } diff --git a/tests/PHPCI/Command/InstallCommandTest.php b/tests/PHPCI/Command/InstallCommandTest.php index 884ed719..7aad3716 100644 --- a/tests/PHPCI/Command/InstallCommandTest.php +++ b/tests/PHPCI/Command/InstallCommandTest.php @@ -35,14 +35,13 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase { // We check that there's no interaction with user. $dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper') - ->setMethods(array( - 'ask', - 'askConfirmation', - 'askAndValidate', - 'askHiddenResponse', - 'askHiddenResponseAndValidate', - )) - ->getMock(); + ->setMethods([ + 'ask', + 'askConfirmation', + 'askAndValidate', + 'askHiddenResponse', + 'askHiddenResponseAndValidate', + ])->getMock(); return $dialog; } @@ -55,7 +54,7 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase // Current command, we need to mock all method that interact with // Database & File system. $command = $this->getMockBuilder('PHPCI\\Command\\InstallCommand') - ->setMethods(array( + ->setMethods([ 'reloadConfig', 'verifyNotInstalled', 'verifyDatabaseDetails', @@ -63,8 +62,7 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase 'createAdminUser', 'writeConfigFile', 'checkRequirements', - )) - ->getMock(); + ])->getMock(); $self = $this; @@ -98,17 +96,17 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase protected function getConfig($exclude = null) { - $config = array( - '--db-host' => 'localhost', - '--db-name' => 'phpci1', - '--db-user' => 'phpci2', - '--db-pass' => 'phpci3', - '--admin-mail' => 'phpci@phpci.test', - '--admin-name' => 'phpci4', - '--admin-pass' => 'phpci5', - '--url' => 'http://test.phpci.org', + $config = [ + '--db-host' => 'localhost', + '--db-name' => 'phpci1', + '--db-user' => 'phpci2', + '--db-pass' => 'phpci3', + '--admin-mail' => 'phpci@phpci.test', + '--admin-name' => 'phpci4', + '--admin-pass' => 'phpci5', + '--url' => 'http://test.phpci.org', '--queue-disabled' => null, - ); + ]; if (!is_null($exclude)) { unset($config[$exclude]); diff --git a/tests/PHPCI/Helper/CommandExecutorTest.php b/tests/PHPCI/Helper/CommandExecutorTest.php index feed9485..4e6d5d20 100644 --- a/tests/PHPCI/Helper/CommandExecutorTest.php +++ b/tests/PHPCI/Helper/CommandExecutorTest.php @@ -37,28 +37,28 @@ class CommandExecutorTest extends \PHPUnit_Framework_TestCase public function testGetLastOutput_ReturnsOutputOfCommand() { - $this->testedExecutor->executeCommand(array('echo "%s"', 'Hello World')); + $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']); $output = $this->testedExecutor->getLastOutput(); $this->assertEquals("Hello World", $output); } public function testGetLastOutput_ForgetsPreviousCommandOutput() { - $this->testedExecutor->executeCommand(array('echo "%s"', 'Hello World')); - $this->testedExecutor->executeCommand(array('echo "%s"', 'Hello Tester')); + $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']); + $this->testedExecutor->executeCommand(['echo "%s"', 'Hello Tester']); $output = $this->testedExecutor->getLastOutput(); $this->assertEquals("Hello Tester", $output); } public function testExecuteCommand_ReturnsTrueForValidCommands() { - $returnValue = $this->testedExecutor->executeCommand(array('echo "%s"', 'Hello World')); + $returnValue = $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']); $this->assertTrue($returnValue); } public function testExecuteCommand_ReturnsFalseForInvalidCommands() { - $returnValue = $this->testedExecutor->executeCommand(array('eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World')); + $returnValue = $this->testedExecutor->executeCommand(['eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World']); $this->assertFalse($returnValue); } diff --git a/tests/PHPCI/Helper/MailerFactoryTest.php b/tests/PHPCI/Helper/MailerFactoryTest.php index d59685d1..c9732798 100644 --- a/tests/PHPCI/Helper/MailerFactoryTest.php +++ b/tests/PHPCI/Helper/MailerFactoryTest.php @@ -27,16 +27,16 @@ class MailerFactoryTest extends \PHPUnit_Framework_TestCase */ public function testExecute_TestGetMailConfig() { - $config = array( - 'smtp_address' => 'mail.example.com', - 'smtp_port' => 225, - 'smtp_encryption' => true, - 'smtp_username' => 'example.user', - 'smtp_password' => 'examplepassword', + $config = [ + 'smtp_address' => 'mail.example.com', + 'smtp_port' => 225, + 'smtp_encryption' => true, + 'smtp_username' => 'example.user', + 'smtp_password' => 'examplepassword', 'default_mailto_address' => 'phpci@example.com', - ); + ]; - $factory = new MailerFactory(array('email_settings' => $config)); + $factory = new MailerFactory(['email_settings' => $config]); $this->assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address')); $this->assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port')); @@ -51,16 +51,16 @@ class MailerFactoryTest extends \PHPUnit_Framework_TestCase */ public function testExecute_TestMailer() { - $config = array( - 'smtp_address' => 'mail.example.com', - 'smtp_port' => 225, - 'smtp_encryption' => true, - 'smtp_username' => 'example.user', - 'smtp_password' => 'examplepassword', + $config = [ + 'smtp_address' => 'mail.example.com', + 'smtp_port' => 225, + 'smtp_encryption' => true, + 'smtp_username' => 'example.user', + 'smtp_password' => 'examplepassword', 'default_mailto_address' => 'phpci@example.com', - ); + ]; - $factory = new MailerFactory(array('email_settings' => $config)); + $factory = new MailerFactory(['email_settings' => $config]); $mailer = $factory->getSwiftMailerFromConfig(); $this->assertEquals($config['smtp_address'], $mailer->getTransport()->getHost()); diff --git a/tests/PHPCI/Logging/LoggerConfigTest.php b/tests/PHPCI/Logging/LoggerConfigTest.php index 9d8acd5a..2e1729d2 100644 --- a/tests/PHPCI/Logging/LoggerConfigTest.php +++ b/tests/PHPCI/Logging/LoggerConfigTest.php @@ -31,11 +31,11 @@ class LoggerConfigTest extends \PHPUnit_Framework_TestCase public function testGetFor_AttachesAlwaysPresentHandlers() { $expectedHandler = new \Monolog\Handler\NullHandler(); - $config = new LoggerConfig(array( + $config = new LoggerConfig([ LoggerConfig::KEY_ALWAYS_LOADED => function() use ($expectedHandler) { - return array($expectedHandler); + return [$expectedHandler]; } - )); + ]); /** @var \Monolog\Logger $logger */ $logger = $config->getFor("something"); @@ -47,11 +47,11 @@ class LoggerConfigTest extends \PHPUnit_Framework_TestCase public function testGetFor_AttachesSpecificHandlers() { $expectedHandler = new \Monolog\Handler\NullHandler(); - $config = new LoggerConfig(array( + $config = new LoggerConfig([ "Specific" => function() use ($expectedHandler) { - return array($expectedHandler); + return [$expectedHandler]; } - )); + ]); /** @var \Monolog\Logger $logger */ $logger = $config->getFor("Specific"); @@ -65,14 +65,14 @@ class LoggerConfigTest extends \PHPUnit_Framework_TestCase $expectedHandler = new \Monolog\Handler\NullHandler(); $alternativeHandler = new \Monolog\Handler\NullHandler(); - $config = new LoggerConfig(array( + $config = new LoggerConfig([ "Specific" => function() use ($expectedHandler) { - return array($expectedHandler); + return [$expectedHandler]; }, "Other" => function() use ($alternativeHandler) { - return array($alternativeHandler); + return [$alternativeHandler]; } - )); + ]); /** @var \Monolog\Logger $logger */ $logger = $config->getFor("Specific"); diff --git a/tests/PHPCI/Model/BuildTest.php b/tests/PHPCI/Model/BuildTest.php index 24508fe7..b01370a5 100644 --- a/tests/PHPCI/Model/BuildTest.php +++ b/tests/PHPCI/Model/BuildTest.php @@ -70,10 +70,10 @@ class BuildTest extends \PHPUnit_Framework_TestCase */ public function testExecute_TestBuildExtra() { - $info = array( + $info = [ 'item1' => 'Item One', 'item2' => 2, - ); + ]; $build = new Build(); $build->setExtra(json_encode($info)); diff --git a/tests/PHPCI/Model/ProjectTest.php b/tests/PHPCI/Model/ProjectTest.php index b3bfb799..567eb874 100644 --- a/tests/PHPCI/Model/ProjectTest.php +++ b/tests/PHPCI/Model/ProjectTest.php @@ -95,10 +95,10 @@ class ProjectTest extends \PHPUnit_Framework_TestCase */ public function testExecute_TestProjectAccessInformation() { - $info = array( + $info = [ 'item1' => 'Item One', 'item2' => 2, - ); + ]; $project = new Project(); $project->setAccessInformation($info); diff --git a/tests/PHPCI/Plugin/EmailTest.php b/tests/PHPCI/Plugin/EmailTest.php index 19b4e12f..eb2b044c 100644 --- a/tests/PHPCI/Plugin/EmailTest.php +++ b/tests/PHPCI/Plugin/EmailTest.php @@ -116,15 +116,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->mockCiBuilder->expects($this->any()) ->method('getSystemConfig') ->with('phpci') - ->will( - $this->returnValue( - array( - 'email_settings' => array( - 'from_address' => "test-from-address@example.com" - ) - ) - ) - ); + ->will($this->returnValue(['email_settings' => ['from_address' => "test-from-address@example.com"]])); } protected function loadEmailPluginWithOptions($arrOptions = [], $buildStatus = null, $mailDelivered = true) @@ -144,12 +136,12 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->testedEmailPlugin = $this->getMock( '\PHPCI\Plugin\Email', - array('sendEmail'), - array( + ['sendEmail'], + [ $this->mockCiBuilder, $this->mockBuild, $arrOptions - ) + ] ); $this->testedEmailPlugin->expects($this->any()) @@ -184,12 +176,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ public function testBuildsBasicEmails() { - $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), - Build::STATUS_SUCCESS - ); + $this->loadEmailPluginWithOptions(['addresses' => ['test-receiver@example.com']], Build::STATUS_SUCCESS); $this->testedEmailPlugin->execute(); @@ -201,12 +188,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ public function testBuildsDefaultEmails() { - $this->loadEmailPluginWithOptions( - array( - 'default_mailto_address' => 'default-mailto-address@example.com' - ), - Build::STATUS_SUCCESS - ); + $this->loadEmailPluginWithOptions(['default_mailto_address' => 'default-mailto-address@example.com'], Build::STATUS_SUCCESS); $this->testedEmailPlugin->execute(); @@ -218,11 +200,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ public function testExecute_UniqueRecipientsFromWithCommitter() { - $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com', 'test-receiver2@example.com') - ) - ); + $this->loadEmailPluginWithOptions(['addresses' => ['test-receiver@example.com', 'test-receiver2@example.com']]); $returnValue = $this->testedEmailPlugin->execute(); $this->assertTrue($returnValue); @@ -238,12 +216,10 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ public function testExecute_UniqueRecipientsWithCommitter() { - $this->loadEmailPluginWithOptions( - array( - 'committer' => true, - 'addresses' => array('test-receiver@example.com', 'committer@test.com') - ) - ); + $this->loadEmailPluginWithOptions([ + 'committer' => true, + 'addresses' => ['test-receiver@example.com', 'committer@test.com'] + ]); $returnValue = $this->testedEmailPlugin->execute(); $this->assertTrue($returnValue); @@ -258,25 +234,25 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testCcDefaultEmails() { $this->loadEmailPluginWithOptions( - array( + [ 'default_mailto_address' => 'default-mailto-address@example.com', - 'cc' => array( + 'cc' => [ 'cc-email-1@example.com', 'cc-email-2@example.com', 'cc-email-3@example.com', - ), - ), + ], + ], Build::STATUS_SUCCESS ); $this->testedEmailPlugin->execute(); $this->assertEquals( - array( + [ 'cc-email-1@example.com', 'cc-email-2@example.com', 'cc-email-3@example.com', - ), + ], $this->message['cc'] ); } @@ -287,9 +263,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testBuildsCommitterEmails() { $this->loadEmailPluginWithOptions( - array( + [ 'committer' => true - ), + ], Build::STATUS_SUCCESS ); @@ -304,9 +280,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testMailSuccessfulBuildHaveProjectName() { $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), + [ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_SUCCESS ); @@ -322,9 +298,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testMailFailingBuildHaveProjectName() { $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), + [ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_FAILED ); @@ -340,9 +316,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testMailSuccessfulBuildHaveStatus() { $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), + [ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_SUCCESS ); @@ -358,9 +334,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testMailFailingBuildHaveStatus() { $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), + [ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_FAILED ); @@ -376,9 +352,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testMailDeliverySuccess() { $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), + [ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_FAILED, true ); @@ -394,9 +370,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase public function testMailDeliveryFail() { $this->loadEmailPluginWithOptions( - array( - 'addresses' => array('test-receiver@example.com') - ), + [ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_FAILED, false ); diff --git a/tests/PHPCI/Plugin/PharTest.php b/tests/PHPCI/Plugin/PharTest.php index 7de8c272..10d907fe 100644 --- a/tests/PHPCI/Plugin/PharTest.php +++ b/tests/PHPCI/Plugin/PharTest.php @@ -61,7 +61,7 @@ class PharTest extends \PHPUnit_Framework_TestCase protected function cleanSource() { if ($this->directory) { - $filenames = array( + $filenames = [ '/build.phar', '/stub.php', '/views/index.phtml', @@ -70,7 +70,7 @@ class PharTest extends \PHPUnit_Framework_TestCase '/config', '/two.php', '/one.php', - ); + ]; foreach ($filenames as $filename) { if (is_dir($this->directory . $filename)) { rmdir($this->directory . $filename); @@ -104,7 +104,7 @@ class PharTest extends \PHPUnit_Framework_TestCase $plugin->getPHPCI()->buildPath = 'foo'; $this->assertEquals('foo', $plugin->getDirectory()); - $plugin = $this->getPlugin(array('directory' => 'dirname')); + $plugin = $this->getPlugin(['directory' => 'dirname']); $this->assertEquals('dirname', $plugin->getDirectory()); } @@ -113,7 +113,7 @@ class PharTest extends \PHPUnit_Framework_TestCase $plugin = $this->getPlugin(); $this->assertEquals('build.phar', $plugin->getFilename()); - $plugin = $this->getPlugin(array('filename' => 'another.phar')); + $plugin = $this->getPlugin(['filename' => 'another.phar']); $this->assertEquals('another.phar', $plugin->getFilename()); } @@ -122,7 +122,7 @@ class PharTest extends \PHPUnit_Framework_TestCase $plugin = $this->getPlugin(); $this->assertEquals('/\.php$/', $plugin->getRegExp()); - $plugin = $this->getPlugin(array('regexp' => '/\.(php|phtml)$/')); + $plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']); $this->assertEquals('/\.(php|phtml)$/', $plugin->getRegExp()); } @@ -131,7 +131,7 @@ class PharTest extends \PHPUnit_Framework_TestCase $plugin = $this->getPlugin(); $this->assertNull($plugin->getStub()); - $plugin = $this->getPlugin(array('stub' => 'stub.php')); + $plugin = $this->getPlugin(['stub' => 'stub.php']); $this->assertEquals('stub.php', $plugin->getStub()); } @@ -157,7 +157,7 @@ class PharTest extends \PHPUnit_Framework_TestCase { $this->checkReadonly(); - $plugin = $this->getPlugin(array('regexp' => '/\.(php|phtml)$/')); + $plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']); $path = $this->buildSource(); $plugin->getPHPCI()->buildPath = $path; @@ -184,7 +184,7 @@ STUB; $path = $this->buildSource(); file_put_contents($path . '/stub.php', $content); - $plugin = $this->getPlugin(array('stub' => 'stub.php')); + $plugin = $this->getPlugin(['stub' => 'stub.php']); $plugin->getPHPCI()->buildPath = $path; $this->assertTrue($plugin->execute()); @@ -200,7 +200,7 @@ STUB; $directory = $this->buildTemp(); - $plugin = $this->getPlugin(array('directory' => $directory)); + $plugin = $this->getPlugin(['directory' => $directory]); $plugin->getPHPCI()->buildPath = $this->buildSource(); $this->assertFalse($plugin->execute()); diff --git a/tests/PHPCI/Plugin/Util/ExamplePluginConfig.php b/tests/PHPCI/Plugin/Util/ExamplePluginConfig.php index 5b0819c4..34c717aa 100644 --- a/tests/PHPCI/Plugin/Util/ExamplePluginConfig.php +++ b/tests/PHPCI/Plugin/Util/ExamplePluginConfig.php @@ -12,9 +12,9 @@ return function (PHPCI\Plugin\Util\Factory $factory) { $factory->registerResource( // This function will be called when the resource is needed. function() { - return array( + return [ 'bar' => "Hello", - ); + ]; }, "requiredArgument", null diff --git a/tests/PHPCI/Plugin/Util/ExecutorTest.php b/tests/PHPCI/Plugin/Util/ExecutorTest.php index 921fe489..6ccff5ac 100644 --- a/tests/PHPCI/Plugin/Util/ExecutorTest.php +++ b/tests/PHPCI/Plugin/Util/ExecutorTest.php @@ -130,12 +130,12 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase $behatPluginOptions = []; $build = new \PHPCI\Model\Build(); - $config = array( - 'stageOne' => array( + $config = [ + 'stageOne' => [ 'PhpUnit' => $phpUnitPluginOptions, - 'Behat' => $behatPluginOptions, - ) - ); + 'Behat' => $behatPluginOptions, + ] + ]; $pluginNamespace = 'PHPCI\\Plugin\\'; diff --git a/tests/PHPCI/Plugin/Util/FactoryTest.php b/tests/PHPCI/Plugin/Util/FactoryTest.php index 76007a40..823840e6 100644 --- a/tests/PHPCI/Plugin/Util/FactoryTest.php +++ b/tests/PHPCI/Plugin/Util/FactoryTest.php @@ -50,7 +50,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase { public function testRegisterResourceThrowsExceptionIfLoaderIsntFunction() { $this->setExpectedException('InvalidArgumentException', '$loader is expected to be a function'); - $this->testedFactory->registerResource(array("dummy"), "TestName", "TestClass"); + $this->testedFactory->registerResource(["dummy"], "TestName", "TestClass"); } public function testBuildPluginWorksWithConstructorlessPlugins() @@ -131,9 +131,9 @@ class FactoryTest extends \PHPUnit_Framework_TestCase { { $pluginClass = $this->getFakePluginClassName('ExamplePluginFull'); - $expectedArgs = array( + $expectedArgs = [ 'thing' => "stuff" - ); + ]; $this->registerBuildAndBuilder(); @@ -167,7 +167,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase { // The Example config file defines an array as the resource. $this->assertEquals( - array("bar" => "Hello"), + ["bar" => "Hello"], $plugin->RequiredArgument ); } diff --git a/tests/PHPCI/Service/BuildServiceTest.php b/tests/PHPCI/Service/BuildServiceTest.php index 3c96b131..30df6d9a 100644 --- a/tests/PHPCI/Service/BuildServiceTest.php +++ b/tests/PHPCI/Service/BuildServiceTest.php @@ -91,7 +91,7 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase $project->setType('bitbucket'); $project->setId(101); - $returnValue = $this->testedService->createBuild($project, null, null, null, null, array('item1' => 1001)); + $returnValue = $this->testedService->createBuild($project, null, null, null, null, ['item1' => 1001]); $this->assertEquals(1001, $returnValue->getExtra('item1')); } @@ -112,7 +112,7 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase $build->setFinished(new \DateTime()); $build->setCommitMessage('test'); $build->setCommitterEmail('test@example.com'); - $build->setExtra(json_encode(array('item1' => 1001))); + $build->setExtra(json_encode(['item1' => 1001])); $returnValue = $this->testedService->createDuplicateBuild($build);