izzum\statemachine\persistence\RedisTest::shouldBeAbleToLoadConfigurationFromSpecificConfigurationKey PHP 메소드

shouldBeAbleToLoadConfigurationFromSpecificConfigurationKey() 공개 메소드

    public function shouldBeAbleToLoadConfigurationFromSpecificConfigurationKey()
    {
        $redis = new Redis();
        $redis->setDatabase(15);
        //clear the redis database for testing
        $redis->flushdb();
        $identifier = new Identifier(1, 'test-machine');
        $machine = new StateMachine(new Context($identifier, null, $redis));
        //create the loader
        //get the configuration from the json file
        $configuration = file_get_contents(__DIR__ . '/../loader/fixture-example.json');
        //set it. normally, this would be done by a seperate process that has already loaded the configuration
        $redis->set(sprintf(Redis::KEY_CONFIGURATION_SPECIFIC, $redis->getConfigurationKey(), 'test-machine'), $configuration);
        //load the machine
        $count = $redis->load($machine);
        $this->assertEquals(4, $count, 'expect 4 transitions to be loaded');
        $this->assertCount(4, $machine->getTransitions(), 'there is a regex transition that adds 2 transitions (a-c and b-c)');
        $this->assertCount(4, $machine->getStates());
        $this->assertNotNull($redis->toString());
        $this->assertNotNull($redis . '');
        $this->assertFalse($redis->isPersisted($identifier));
        $this->assertTrue($machine->add('add to the backend'));
        $this->assertFalse($machine->add('add to the backend'), 'already added');
        $this->assertEquals('a', $machine->getCurrentState());
        $this->assertTrue($redis->isPersisted($identifier));
        $this->assertTrue($machine->run('run from a to b'));
        $this->assertEquals('b', $machine->getCurrentState());
        $this->assertTrue($redis->isPersisted($identifier));
        $this->assertTrue($machine->run('some message here to store'));
        $this->assertEquals('done', $machine->getCurrentState());
        $ids = $redis->getEntityIds('test-machine');
        $this->assertEquals(1, count($ids));
        //destroy
        $redis = null;
    }