/**
  * Do the Artisan commands fire?
  */
 public function testCommands()
 {
     $self = $this;
     $this->prepareSpecify();
     $this->specify('Boots', function () use($self) {
         $target = $self->getProvider(['package']);
         $target->shouldReceive('package');
         $target->boot();
     });
     $this->prepareSpecify();
     $this->specify('Identifies provisions', function () use($self) {
         $target = $self->getProvider();
         verify($target->provides())->notEmpty();
     });
     $this->prepareSpecify();
     $this->specify('Binds to application', function () use($self) {
         App::shouldReceive('bind')->with('/^toolbox\\.commands\\./', Mockery::on(function ($closure) {
             $command = $closure();
             verify_that('is a command', is_a($command, 'Illuminate\\Console\\Command'));
             return true;
         }));
         Event::shouldReceive('listen')->with('toolbox.build', Mockery::on(function ($closure) {
             $app = Mockery::mock('Illuminate\\Console\\Application[call]');
             $app->shouldReceive('call');
             $command = $closure($app);
             return true;
         }));
         $target = $self->getProvider(['commands']);
         $target->shouldReceive('commands')->with(Mockery::type('array'));
         $target->register();
     });
 }
 public function testClassIsInitializedProperly()
 {
     verify("the type is set to 'schema'", $this->import->type)->equals("schema");
     verify("the vocabid is set to '81'", $this->import->vocabId)->equals(81);
     verify("the file is set to 'updatedata.csv'", $this->import->file)->equals("updatedata.csv");
     verify("the type is set to 'schema'", $this->import->type)->equals("schema");
     verify_that(is_integer($this->import->vocabId));
     verify("the path is set", $this->import->importFolder . $this->import->file)->equals("/var/www/registry/plugins/jpAdminGeneratorPlugin/lib/ImportVocab/tests/_data/updatedata.csv");
 }
 public function testWorkflowAccessorSuccess()
 {
     $src = new WorkflowFileSource();
     $src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A' => ['label' => 'label A', 'transition' => ['B', 'C']], 'B' => [], 'C' => []]]);
     $w = $src->getWorkflow('wid');
     verify_that($w != null);
     $this->specify('initial status can be obtained through workflow', function () use($w) {
         expect_that($w->getInitialStatus() instanceof StatusInterface);
         expect_that($w->getInitialStatus()->getId() == $w->getInitialStatusId());
     });
 }
 public function testReturnReportWithNothing()
 {
     /** @var Item05|ActiveWorkflowBehavior $model */
     // prepare
     $model = new Item05();
     $model->status = 'Item05Workflow/new';
     verify_that($model->save());
     // test
     $report = $model->getNextStatuses();
     $this->assertCount(2, $report, ' report contains 2 entries as 2 statuses can be reached from "new"');
     $this->assertArrayHasKey('Item05Workflow/correction', $report, '  a transition exists between "new" and "correction" ');
     $this->assertArrayHasKey('Item05Workflow/published', $report, '  a transition exists between "new" and "published" ');
     $this->assertTrue(!isset($report['Item05Workflow/correction']['isValid']));
     $this->assertTrue(!isset($report['Item05Workflow/correction']['validation']));
     $this->assertTrue(!isset($report['Item05Workflow/correction']['event']));
     $this->assertTrue(!isset($report['Item05Workflow/published']['isValid']));
     $this->assertTrue(!isset($report['Item05Workflow/published']['validation']));
     $this->assertTrue(!isset($report['Item05Workflow/published']['event']));
 }
Exemple #5
0
 public function testVerifyThat()
 {
     verify_that(12);
     verify_that('hello world');
     verify_that(array('hello'));
 }
Exemple #6
0
 /**
  * Tests value conversion for returning an array.
  *
  * @author Bas Stottelaar <*****@*****.**>
  * @since  2016-07-25
  */
 public function testConvertArrayReturnsArray()
 {
     $this->specify('Test value conversion to return an array.', function () {
         $validation = new Validation();
         $validation->add('type', new Uniqueness(['convert' => function (array $values) {
             $values;
             return null;
         }]));
         try {
             $validation->validate(null, $this->robot);
             verify_that(false);
         } catch (\Exception $e) {
             verify_that(true);
         }
     });
 }
 public function testSmokeRedisToDb()
 {
     //$this->markTestSkipped();
     $master = $this->masterRedisModel;
     $slave = $this->slaveModel;
     $config = ['class' => ArSyncBehavior::className(), 'slaveModel' => DbSlave::className(), 'slaveScenario' => 'sync', 'fieldMap' => ['id' => 'id', 'title' => 'name', 'foo' => 'foo', 'bar' => 'bar', 'baz' => function ($master) {
         return $master->baz * 2;
     }]];
     $this->specify('testAutoSync', function () use($master, $slave, $config) {
         $this->clearModel($slave);
         $this->clearModel($master);
         $master->attachBehavior('ArSyncBehavior', $config);
         $master->setIsNewRecord(true);
         verify_not($slave::findOne(15), 'slave record not exxists');
         $master->setAttributes(['id' => 15, 'name' => 'lala', 'foo' => 'bar', 'baz' => 10], false);
         verify_that($master->save());
         $slaveSync = $slave::findOne(15);
         verify_that($slaveSync, 'slave model appear ');
         /**@var Verify* */
         verify('fieldMap success', $slaveSync->title)->equals('lala');
         verify('default values success', $slaveSync->bar)->equals('masterdefault');
         verify('closured values success', $slaveSync->baz)->equals(20);
     });
     $this->specify('test update record', function () use($master, $slave, $config) {
         $model = $master::findOne(15);
         verify_that($model);
         $model->attachBehavior('ArSyncBehavior', $config);
         $model->name = 'UpdatedName';
         verify_that($model->update());
         $slaveSync = $slave::findOne(15);
         verify('slave record updated', $slaveSync->title)->equals('UpdatedName');
         $model->delete();
         verify_not($slave::findOne(15), 'after delete master, slave removed');
     });
     $this->specify('testManualSync', function () use($master, $slave, $config) {
         $this->clearModel($slave);
         $this->clearModel($master);
         verify('slave data empty', $slave::find()->count())->equals(0);
         $master->detachBehavior('ArSyncBehavior');
         verify_not($master->hasMethod('syncAll'), 'behavior not attached');
         //fill some data
         /**@var RedisMaster $model */
         $ids = [];
         for ($i = 0; $i < 5; $i++) {
             $model = new $master();
             $model->setAttributes(['name' => 'foo' . $i, 'foo' => 'bar' . $i, 'baz' => 10 + $i]);
             verify_that($model->save());
             $ids[] = $model->getPrimaryKey();
         }
         verify('slave data empty yet, because behavior not attached', $slave::find()->count())->equals(0);
         $master->attachBehavior('ArSyncBehavior', $config);
         $master->syncAll();
         verify('data synced', $slave::find()->where([$slave->primaryKey()[0] => $ids])->count())->equals(5);
         //save not valid data
         $model = new $master();
         $model->attachBehavior('ArSyncBehavior', $config);
         $model->setAttributes(['name' => 'baddata'], false);
         verify_not($model->save());
         verify('slave not changed', $slave::find()->count())->equals(5);
         $master->syncAll(true);
         verify('slave not changed', $slave::find()->count())->equals(5);
         $models = $master::findAll($ids);
         foreach ($models as $model) {
             if ($model->baz == 10) {
                 verify_that($model->delete() !== false);
             } else {
                 $model->name = str_replace('foo', 'boo', $model->name);
                 $model->updateAttributes(['name']);
             }
         }
         verify('slave not changed', $slave::find()->count())->equals(5);
         $master->syncAll();
         verify('slave count changed', $slave::find()->count())->equals(4);
         $slaves = $slave::find()->where(['in', $slave->primaryKey(), $ids])->all();
         foreach ($slaves as $updSlave) {
             verify('slave title changed', $updSlave->title)->contains('boo');
         }
         $master->clearSlave();
         verify('slave must be empty', $slave::find()->count())->equals(0);
     });
     $this->specify('test two-way binding', function () use($master, $slave, $config) {
         $this->clearModel($master);
         $this->clearModel($slave);
         $slaveConfig = ['class' => ArSyncBehavior::className(), 'slaveModel' => RedisMaster::className(), 'saveScenarios' => ['default'], 'deleteScenarios' => [], 'slaveScenario' => 'sync', 'fieldMap' => ['foo' => 'foo', 'bar' => 'bar']];
         Event::on(RedisMaster::className(), ActiveRecord::EVENT_INIT, function ($event) use($config) {
             $event->sender->attachBehavior('ArSyncBehavior', $config);
         });
         Event::on(DbSlave::className(), \yii\db\ActiveRecord::EVENT_INIT, function ($event) use($slaveConfig) {
             $event->sender->attachBehavior('ArSyncBehavior', $slaveConfig);
         });
         /**@var RedisMaster $model */
         $ids = [];
         for ($i = 0; $i < 5; $i++) {
             $model = new $master();
             verify_that($model->getBehavior('ArSyncBehavior'));
             $model->setAttributes(['name' => 'foo' . $i, 'foo' => 'foo' . $i, 'bar' => 'bar' . $i, 'baz' => 10 + $i]);
             verify_that($model->save());
             $ids[] = $model->getPrimaryKey();
         }
         verify('slave count changed', $slave::find()->where(['in', $slave->primaryKey(), $ids])->count())->equals(5);
         $slaves = $slave::find()->where(['in', $slave->primaryKey(), $ids])->all();
         foreach ($slaves as $updSlave) {
             verify_that($updSlave->getBehavior('ArSyncBehavior'));
             $updSlave->foo = 'new_' . $updSlave->foo;
             $updSlave->bar = 'new_' . $updSlave->bar;
             $updSlave->save();
         }
         $masters = $master::find()->where(['in', $master->primaryKey(), $ids])->all();
         foreach ($masters as $newMaster) {
             verify('records was updated', $newMaster->foo)->startsWith('new_');
             verify('records was updated', $newMaster->bar)->startsWith('new_');
         }
     });
     $this->specify('test error callback', function () use($master, $slave, $config) {
         $this->clearModel($slave);
         $errors = [];
         $config['errorSaveCallback'] = function ($slave) use(&$errors) {
             array_push($errors, $slave->errors);
             throw new InvalidValueException('fail save');
         };
         $master->setIsNewRecord(true);
         $master->attachBehavior('ArSyncBehavior', $config);
         verify('slave data empty', $slave::find()->count())->equals(0);
         verify('errors empty', count($errors))->equals(0);
         //save not valid data with skip rules
         $master->setAttributes(['name' => 'baddata', 'foo' => time()], false);
         $this->expectException(InvalidValueException::class);
         verify_that($master->save(false));
         verify('slave not changed for' . $master->id, $slave::find()->count())->equals(0);
         verify('errors not empty', count($errors))->greaterThan(0);
     });
 }
 public function testEnterWorkflowSuccess()
 {
     $o = new Item08();
     $o->getBehavior('w1')->enterWorkflow();
     $o->getBehavior('w2')->enterWorkflow();
     verify_that($o->getBehavior('w1')->getWorkflowStatus()->getId() == 'Item08Workflow1/draft');
     verify_that($o->getBehavior('w2')->getWorkflowStatus()->getId() == 'Item08Workflow2/success');
 }
 public function testStatusAccessorSuccess()
 {
     $this->src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A' => ['label' => 'label A', 'transition' => ['B', 'C']], 'B' => [], 'C' => []]]);
     $w = $this->src->getWorkflow('wid');
     verify_that($w != null);
     $this->specify('transitions can be obtained through status', function () {
         $status = $this->src->getStatus('wid/A');
         expect_that($status != null);
         $tr = $status->getTransitions();
         expect_that(is_array($tr));
         expect(count($tr))->equals(2);
         $keys = array_keys($tr);
         expect($keys)->equals(['wid/B', 'wid/C']);
         expect_that($tr['wid/B'] instanceof TransitionInterface);
         expect_that($tr['wid/C'] instanceof TransitionInterface);
     });
     $this->specify('parent workflow can be obtained through status', function () {
         $status = $this->src->getStatus('wid/A');
         expect_that($status != null);
         $wrk = $status->getWorkflow();
         expect_that($wrk != null);
         verify_that($wrk instanceof WorkflowInterface);
         verify($wrk->getId())->equals('wid');
     });
 }
Exemple #10
0
 /**
  * Tests getMessages in case of non existent type request
  *
  * @issue  11941
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-07-03
  */
 public function testGetNonExistentType()
 {
     $this->specify('The getMessages() method does not return an empty array in case of non existent type request', function () {
         $flash = $this->getFlash();
         $flash->error('sample error');
         expect($flash->getMessages('success', false))->equals([]);
         verify_that(count($flash->getMessages()) === 1);
     });
 }
 public function testEnterWorkflowSuccess()
 {
     /** @var Item08|ActiveWorkflowBehavior $o */
     $o = new Item08();
     /** @var ActiveWorkflowBehavior $b1 */
     $b1 = $o->getBehavior('w1');
     $b1->enterWorkflow();
     /** @var ActiveWorkflowBehavior $b2 */
     $b2 = $o->getBehavior('w2');
     $b2->enterWorkflow();
     verify_that($b1->getWorkflowStatus()->getId() == 'Item08Workflow1/draft');
     verify_that($b2->getWorkflowStatus()->getId() == 'Item08Workflow2/success');
 }