File tree Expand file tree Collapse file tree 10 files changed +221
-3
lines changed Expand file tree Collapse file tree 10 files changed +221
-3
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.6
5
+ - 7.1
6
+
7
+ # faster builds on new travis setup not using sudo
8
+ sudo : false
9
+
10
+ # cache vendor dirs
11
+ cache :
12
+ directories :
13
+ - $HOME/.composer/cache
14
+ - vendor
15
+
16
+ install :
17
+ - travis_retry composer self-update && composer --version
18
+ - travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0"
19
+ - export PATH="$HOME/.composer/vendor/bin:$PATH"
20
+ - travis_retry composer install --prefer-dist --no-interaction
21
+
22
+ script :
23
+ - vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
24
+ - phpunit --verbose $PHPUNIT_FLAGS
Original file line number Diff line number Diff line change @@ -43,9 +43,9 @@ public function init()
43
43
parent ::init ();
44
44
45
45
if (Yii::$ app ->has ($ this ->schedule )) {
46
- $ this ->schedule = Instance::ensure ($ this ->schedule , Schedule::className () );
46
+ $ this ->schedule = Instance::ensure ($ this ->schedule , Schedule::class );
47
47
} else {
48
- $ this ->schedule = Yii::createObject (Schedule::className () );
48
+ $ this ->schedule = Yii::createObject (Schedule::class );
49
49
}
50
50
}
51
51
Original file line number Diff line number Diff line change 14
14
}
15
15
],
16
16
"require" : {
17
- "php" : " >=5.4.0 " ,
17
+ "php" : " >=5.6 " ,
18
18
"yiisoft/yii2" : " 2.0.*" ,
19
19
"symfony/process" : " 2.6.*" ,
20
20
"mtdowling/cron-expression" : " ~1.0" ,
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 =" Yii2mod 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 \scheduling \tests ;
4
+
5
+ use Yii ;
6
+ use yii2mod \scheduling \Schedule ;
7
+
8
+ /**
9
+ * Class ScheduleTest
10
+ *
11
+ * @package yii2mod\scheduling\tests
12
+ */
13
+ class ScheduleTest extends TestCase
14
+ {
15
+ /**
16
+ * @var Schedule
17
+ */
18
+ private $ _schedule ;
19
+
20
+ /**
21
+ * @inheritdoc
22
+ */
23
+ protected function setUp ()
24
+ {
25
+ parent ::setUp ();
26
+
27
+ $ this ->_schedule = Yii::createObject (Schedule::class);
28
+ $ this ->importScheduleFile ();
29
+ }
30
+
31
+ // Tests :
32
+ public function testGetEvents ()
33
+ {
34
+ $ events = $ this ->_schedule ->getEvents ();
35
+ $ event = $ events [0 ];
36
+
37
+ $ this ->assertNotEmpty ($ events );
38
+ $ this ->assertCount (2 , $ events );
39
+ $ this ->assertEquals ('Show list of files ' , $ event ->description );
40
+ $ this ->assertEquals ('ls ' , $ event ->command );
41
+ $ this ->assertEquals ('* * * * * * ' , $ event ->expression );
42
+
43
+ $ event = $ events [1 ];
44
+
45
+ $ this ->assertEquals ('Execute migrations ' , $ event ->description );
46
+ $ this ->assertContains ('yii migrate ' , $ event ->command );
47
+ $ this ->assertEquals ('0 0 * * * * ' , $ event ->expression );
48
+ }
49
+
50
+ /**
51
+ * Import schedule file
52
+ */
53
+ protected function importScheduleFile ()
54
+ {
55
+ $ scheduleFile = Yii::getAlias ('@yii2mod/tests/scheduling/data/schedule.php ' );
56
+
57
+ $ schedule = $ this ->_schedule ;
58
+ call_user_func (function () use ($ schedule , $ scheduleFile ) {
59
+ include $ scheduleFile ;
60
+ });
61
+ }
62
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace yii2mod \scheduling \tests ;
4
+
5
+ use Yii ;
6
+ use yii \helpers \ArrayHelper ;
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
+
17
+ $ this ->mockApplication ();
18
+ }
19
+
20
+ protected function tearDown ()
21
+ {
22
+ $ this ->destroyApplication ();
23
+ }
24
+
25
+ /**
26
+ * Populates Yii::$app with a new application
27
+ * The application will be destroyed on tearDown() automatically.
28
+ *
29
+ * @param array $config The application configuration, if needed
30
+ * @param string $appClass name of the application class to create
31
+ */
32
+ protected function mockApplication ($ config = [], $ appClass = '\yii\console\Application ' )
33
+ {
34
+ new $ appClass (ArrayHelper::merge ([
35
+ 'id ' => 'testapp ' ,
36
+ 'basePath ' => __DIR__ ,
37
+ 'vendorPath ' => $ this ->getVendorPath (),
38
+ ], $ config ));
39
+ }
40
+
41
+ /**
42
+ * @return string vendor path
43
+ */
44
+ protected function getVendorPath ()
45
+ {
46
+ return dirname (__DIR__ ) . '/vendor ' ;
47
+ }
48
+
49
+ /**
50
+ * Destroys application in Yii::$app by setting it to null.
51
+ */
52
+ protected function destroyApplication ()
53
+ {
54
+ Yii::$ app = null ;
55
+ }
56
+ }
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 ' );
14
+
15
+ Yii::setAlias ('@yii2mod/tests/scheduling ' , __DIR__ );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /* @var $schedule \yii2mod\scheduling\Schedule */
4
+ $ schedule ->exec ('ls ' )->description ('Show list of files ' )->everyMinute ();
5
+ $ schedule ->command ('migrate ' )->description ('Execute migrations ' )->daily ();
You can’t perform that action at this time.
0 commit comments