Ejemplo n.º 1
0
 /**
  * check if strategies are called
  *
  * @return void
  */
 public function testLoadCallsStrategy()
 {
     $jsonDef = array($this->getMockBuilder('\\Graviton\\GeneratorBundle\\Definition\\JsonDefinition')->disableOriginalConstructor()->getMock());
     $strategy = $this->getMock('\\Graviton\\GeneratorBundle\\Definition\\Loader\\Strategy\\StrategyInterface');
     $strategy->expects($this->once())->method('supports')->with(null)->will($this->returnValue(true));
     $strategy->expects($this->once())->method('load')->with(null)->will($this->returnValue($jsonDef));
     $sut = new Loader();
     $sut->addStrategy($strategy);
     $this->assertEquals($jsonDef, $sut->load(null));
 }
Ejemplo n.º 2
0
 /**
  * check if schema is invalid
  *
  * @return void
  * @expectedException \HadesArchitect\JsonSchemaBundle\Exception\ViolationException
  */
 public function testLoadInvalidDefinition()
 {
     $json = __METHOD__;
     $errors = [new Error(__FILE__, __CLASS__)];
     $validator = $this->getMockBuilder('Graviton\\JsonSchemaBundle\\Validator\\ValidatorInterface')->disableOriginalConstructor()->setMethods(['validateJsonDefinition'])->getMock();
     $validator->expects($this->once())->method('validateJsonDefinition')->with($json)->willReturn($errors);
     $serializer = $this->getMockBuilder('Jms\\Serializer\\SerializerInterface')->disableOriginalConstructor()->setMethods(['serialize', 'deserialize'])->getMock();
     $serializer->expects($this->never())->method('deserialize');
     $strategy = $this->getMockBuilder('Graviton\\GeneratorBundle\\Definition\\Loader\\Strategy\\StrategyInterface')->getMock();
     $strategy->expects($this->once())->method('supports')->with(null)->will($this->returnValue(true));
     $strategy->expects($this->once())->method('load')->with(null)->will($this->returnValue([$json]));
     $sut = new Loader($validator, $serializer);
     $sut->addStrategy($strategy);
     $sut->load(null);
 }