izzum\statemachine\EntityBuilderTest::testBuilderOverride PHP Метод

testBuilderOverride() публичный Метод

this is also used to check if the caching works
public testBuilderOverride ( )
    public function testBuilderOverride()
    {
        //create Entity in default state. this is enough to pass it
        //to the builder
        $object_1 = new Identifier(-1, 'order');
        $object_2 = new Identifier(-2, 'order');
        $this->assertNotEquals($object_1, $object_2);
        //scenario: call it with same objects to check CACHING! on the differently
        //returned references
        $builder = new EntityBuilderStdClss();
        $result_1 = $builder->getEntity($object_1);
        $this->assertNotEquals($object_1, $result_1, 'returns something different than input');
        //check values
        $this->assertEquals($object_1->getEntityId(), $result_1->entity_id);
        $this->assertEquals($object_1->getMachine(), $result_1->machine);
        //expect same result when we call it again
        $result_2 = $builder->getEntity($object_1);
        $this->assertEquals($object_1->getEntityId(), $result_2->entity_id);
        $this->assertEquals($object_1->getMachine(), $result_2->machine);
        //identity is exactly the same (same cached object)
        $this->assertEquals($result_1, $result_2, 'same identity because cached');
        $this->assertEquals('izzum\\statemachine\\EntityBuilderStdClss', $builder->toString());
        //scenario: call it twice with different object
        $builder = new EntityBuilderStdClss();
        $result_1 = $builder->getEntity($object_1);
        //different result when we call it again
        $result_2 = $builder->getEntity($object_2);
        $this->assertNotEquals($result_1, $result_2);
    }