File tree Expand file tree Collapse file tree 9 files changed +211
-1
lines changed Expand file tree Collapse file tree 9 files changed +211
-1
lines changed Original file line number Diff line number Diff line change 1+ # Ignore all test and documentation for archive
2+ /.gitattributes export-ignore
3+ /.gitignore export-ignore
4+ /.scrutinizer.yml export-ignore
5+ /.travis.yml export-ignore
6+ /phpunit.xml.dist export-ignore
7+ /tests export-ignore
8+ /docs export-ignore
Original file line number Diff line number Diff line change 1+ # phpstorm project files
2+ .idea
3+
4+ # netbeans project files
5+ nbproject
6+
7+ # zend studio for eclipse project files
8+ .buildpath
9+ .project
10+ .settings
11+
12+ # windows thumbnail cache
13+ Thumbs.db
14+
15+ # composer vendor dir
16+ /vendor
17+
18+ /composer.lock
19+
20+ # composer itself is not needed
21+ composer.phar
22+
23+ # Mac DS_Store Files
24+ .DS_Store
25+
26+ # phpunit itself is not needed
27+ phpunit.phar
28+ # local phpunit config
29+ /phpunit.xml
30+
31+ # local tests configuration
32+ /tests /data /config.local.php
33+
34+ # runtime cache
35+ /tests /runtime
Original file line number Diff line number Diff line change 1+ language : php
2+
3+ php :
4+ - 5.4
5+ - 5.5
6+ - 5.6
7+ - 7.0
8+ - hhvm
9+
10+ # run build against hhvm but allow them to fail
11+ # http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail
12+ matrix :
13+ fast_finish : true
14+ allow_failures :
15+ - php : hhvm
16+
17+ # faster builds on new travis setup not using sudo
18+ sudo : false
19+
20+ # cache vendor dirs
21+ cache :
22+ directories :
23+ - $HOME/.composer/cache
24+
25+ install :
26+ - travis_retry composer self-update && composer --version
27+ - travis_retry composer global require "fxp/composer-asset-plugin:~1.1.1"
28+ - export PATH="$HOME/.composer/vendor/bin:$PATH"
29+ - travis_retry composer install --prefer-dist --no-interaction
30+
31+ script :
32+ - phpunit --verbose $PHPUNIT_FLAGS
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <phpunit bootstrap =" ./tests/bootstrap.php"
3+ colors=" true"
4+ convertErrorsToExceptions=" true"
5+ convertNoticesToExceptions=" true"
6+ convertWarningsToExceptions=" true"
7+ stopOnFailure=" false" >
8+ <testsuites >
9+ <testsuite name =" Yii2tech Test Suite" >
10+ <directory >./tests</directory >
11+ </testsuite >
12+ </testsuites >
13+ </phpunit >
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace yii2mod \enum \tests ;
4+
5+ use yii2mod \enum \tests \data \BooleanEnum ;
6+
7+ /**
8+ * Class EnumTest
9+ * @package yii2mod\enum\tests
10+ */
11+ class EnumTest extends TestCase
12+ {
13+ public function testEnumMethods ()
14+ {
15+ $ this ->assertEquals ([1 => 'YES ' , 0 => 'NO ' ], BooleanEnum::getConstantsByValue ());
16+ $ this ->assertEquals (['YES ' => 1 , 'NO ' => 0 ], BooleanEnum::getConstantsByName ());
17+ $ this ->assertEquals ([1 => 'Yes ' , 0 => 'No ' ], BooleanEnum::listData ());
18+ $ this ->assertEquals ('Yes ' , BooleanEnum::getLabel (1 ));
19+ $ this ->assertEquals ('1 ' , BooleanEnum::getValueByName ('Yes ' ));
20+ }
21+
22+ public function testValidation ()
23+ {
24+ $ this ->assertFalse (BooleanEnum::isValidName (1 ));
25+ $ this ->assertTrue (BooleanEnum::isValidName ('YES ' ));
26+ $ this ->assertTrue (BooleanEnum::isValidValue (1 ));
27+ $ this ->assertFalse (BooleanEnum::isValidValue ('YES ' ));
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace yii2mod \enum \tests ;
4+
5+ use yii \helpers \ArrayHelper ;
6+ use Yii ;
7+
8+ /**
9+ * This is the base class for all yii framework unit tests.
10+ */
11+ class TestCase extends \PHPUnit_Framework_TestCase
12+ {
13+ protected function setUp ()
14+ {
15+ parent ::setUp ();
16+ $ this ->mockApplication ();
17+ }
18+
19+ protected function tearDown ()
20+ {
21+ $ this ->destroyApplication ();
22+ }
23+
24+ /**
25+ * Populates Yii::$app with a new application
26+ * The application will be destroyed on tearDown() automatically.
27+ * @param array $config The application configuration, if needed
28+ * @param string $appClass name of the application class to create
29+ */
30+ protected function mockApplication ($ config = [], $ appClass = '\yii\console\Application ' )
31+ {
32+ new $ appClass (ArrayHelper::merge ([
33+ 'id ' => 'testapp ' ,
34+ 'basePath ' => __DIR__ ,
35+ 'vendorPath ' => $ this ->getVendorPath (),
36+ ], $ config ));
37+ }
38+
39+ /**
40+ * @return string vendor path
41+ */
42+ protected function getVendorPath ()
43+ {
44+ return dirname (__DIR__ ) . '/vendor ' ;
45+ }
46+
47+ /**
48+ * Destroys application in Yii::$app by setting it to null.
49+ */
50+ protected function destroyApplication ()
51+ {
52+ Yii::$ app = null ;
53+ }
54+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // ensure we get report on all possible php errors
4+ error_reporting (-1 );
5+
6+ define ('YII_ENABLE_ERROR_HANDLER ' , false );
7+ define ('YII_DEBUG ' , true );
8+
9+ $ _SERVER ['SCRIPT_NAME ' ] = '/ ' . __DIR__ ;
10+ $ _SERVER ['SCRIPT_FILENAME ' ] = __FILE__ ;
11+
12+ require_once (__DIR__ . '/../vendor/autoload.php ' );
13+ require_once (__DIR__ . '/../vendor/yiisoft/yii2/Yii.php ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace yii2mod \enum \tests \data ;
4+
5+ use yii2mod \enum \helpers \BaseEnum ;
6+
7+ /**
8+ * Class BooleanEnum
9+ * @package yii2mod\enum\tests\data
10+ */
11+ class BooleanEnum extends BaseEnum
12+ {
13+ const YES = 1 ;
14+ const NO = 0 ;
15+
16+ /**
17+ * @var string message category
18+ * You can set your own message category for translate the values in the $list property
19+ * Values in the $list property will be automatically translated in the function `listData()`
20+ */
21+ public static $ messageCategory = 'app ' ;
22+
23+ public static $ list = [
24+ self ::YES => 'Yes ' ,
25+ self ::NO => 'No '
26+ ];
27+ }
You can’t perform that action at this time.
0 commit comments