diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..59ea3d7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Ignore all test and documentation for archive +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore +/docs export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e375d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# phpstorm project files +.idea + +# netbeans project files +nbproject + +# zend studio for eclipse project files +.buildpath +.project +.settings + +# windows thumbnail cache +Thumbs.db + +# composer vendor dir +/vendor + +/composer.lock + +# composer itself is not needed +composer.phar + +# Mac DS_Store Files +.DS_Store + +# phpunit itself is not needed +phpunit.phar +# local phpunit config +/phpunit.xml + +# local tests configuration +/tests/data/config.local.php + +# runtime cache +/tests/runtime \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..66e5895 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - hhvm + +# run build against hhvm but allow them to fail +# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail +matrix: + fast_finish: true + allow_failures: + - php: hhvm + +# faster builds on new travis setup not using sudo +sudo: false + +# cache vendor dirs +cache: + directories: + - $HOME/.composer/cache + +install: + - travis_retry composer self-update && composer --version + - travis_retry composer global require "fxp/composer-asset-plugin:~1.1.1" + - export PATH="$HOME/.composer/vendor/bin:$PATH" + - travis_retry composer install --prefer-dist --no-interaction + +script: + - phpunit --verbose $PHPUNIT_FLAGS \ No newline at end of file diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 2659611..0000000 --- a/composer.lock +++ /dev/null @@ -1 +0,0 @@ -composer.lock diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..bc9ece6 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + + ./tests + + + diff --git a/tests/EnumTest.php b/tests/EnumTest.php new file mode 100644 index 0000000..6801005 --- /dev/null +++ b/tests/EnumTest.php @@ -0,0 +1,29 @@ +assertEquals([1 => 'YES', 0 => 'NO'], BooleanEnum::getConstantsByValue()); + $this->assertEquals(['YES' => 1, 'NO' => 0], BooleanEnum::getConstantsByName()); + $this->assertEquals([1 => 'Yes', 0 => 'No'], BooleanEnum::listData()); + $this->assertEquals('Yes', BooleanEnum::getLabel(1)); + $this->assertEquals('1', BooleanEnum::getValueByName('Yes')); + } + + public function testValidation() + { + $this->assertFalse(BooleanEnum::isValidName(1)); + $this->assertTrue(BooleanEnum::isValidName('YES')); + $this->assertTrue(BooleanEnum::isValidValue(1)); + $this->assertFalse(BooleanEnum::isValidValue('YES')); + } +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..a84ba62 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,54 @@ +mockApplication(); + } + + protected function tearDown() + { + $this->destroyApplication(); + } + + /** + * Populates Yii::$app with a new application + * The application will be destroyed on tearDown() automatically. + * @param array $config The application configuration, if needed + * @param string $appClass name of the application class to create + */ + protected function mockApplication($config = [], $appClass = '\yii\console\Application') + { + new $appClass(ArrayHelper::merge([ + 'id' => 'testapp', + 'basePath' => __DIR__, + 'vendorPath' => $this->getVendorPath(), + ], $config)); + } + + /** + * @return string vendor path + */ + protected function getVendorPath() + { + return dirname(__DIR__) . '/vendor'; + } + + /** + * Destroys application in Yii::$app by setting it to null. + */ + protected function destroyApplication() + { + Yii::$app = null; + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..effa70f --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,13 @@ + 'Yes', + self::NO => 'No' + ]; +} \ No newline at end of file