function it_is_not_fine_none_pure_virtual_methods(Contract $contract, Method $method)
 {
     $contract->getName()->willReturn('HttpKernelInterface');
     $contract->allMethods()->willReturn(array($method));
     $method->getBody()->willReturn('echo "Nobody expects the spanish inquisition";');
     $method->getName()->willReturn('handle');
     $this->validate($contract)->shouldHaveType('Memio\\Validator\\Violation\\SomeViolation');
 }
 function it_is_not_fine_with_protected_methods(Contract $contract, Method $method)
 {
     $contract->getName()->willReturn('HttpKernelInterface');
     $contract->allMethods()->willReturn(array($method));
     $method->getVisibility()->willReturn('protected');
     $method->getName()->willReturn('handle');
     $this->validate($contract)->shouldHaveType('Memio\\Validator\\Violation\\SomeViolation');
 }
 function it_also_validates_methods(CollectionValidator $collectionValidator, MethodValidator $methodValidator, Contract $model, Method $method)
 {
     $constants = array();
     $contracts = array();
     $methods = array($method);
     $violationCollection1 = new ViolationCollection();
     $violationCollection2 = new ViolationCollection();
     $violationCollection3 = new ViolationCollection();
     $violationCollection4 = new ViolationCollection();
     $model->getName()->willReturn('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $model->allConstants()->willReturn($constants);
     $model->allContracts()->willReturn($contracts);
     $model->allMethods()->willReturn($methods);
     $collectionValidator->validate($constants)->willReturn($violationCollection1);
     $collectionValidator->validate($contracts)->willReturn($violationCollection2);
     $collectionValidator->validate($methods)->willReturn($violationCollection3);
     $methodValidator->validate($method)->willReturn($violationCollection4);
     $this->validate($model);
 }
 function it_needs_line_after_constants_if_contract_has_both_constants_and_methods(Contract $contract)
 {
     $contract->allConstants()->willReturn(array(1));
     $contract->allMethods()->willReturn(array(2));
     $this->needsLineAfter($contract, self::CONSTANT_BLOCK)->shouldBe(true);
 }
Exemple #5
0
 public function testFull()
 {
     $contract = Contract::make(self::NAME)->extend(new Contract('FirstContract'))->extend(new Contract('SecondContract'))->addConstant(new Constant('FIRST_CONSTANT', '0'))->addConstant(new Constant('SECOND_CONSTANT', "'meh'"))->addMethod(Method::make('firstMethod')->addArgument(new Argument('DateTime', 'firstArgument'))->addArgument(new Argument('array', 'secondArgument'))->addArgument(new Argument('string', 'thirdArgument')))->addMethod(new Method('secondMethod'));
     $generatedCode = $this->prettyPrinter->generateCode($contract);
     $this->assertExpectedCode($generatedCode);
 }
Exemple #6
0
 /**
  * @param Contract $contract
  * @param $filePath
  * @param array $fqns
  * @return $this
  */
 protected function dumpContract(Contract $contract, $filePath, array $fqns = [])
 {
     $fileDir = dirname($filePath);
     $file = File::make($filePath);
     foreach ($contract->allContracts() as $_contract) {
         $fqns[] = $_contract->getFullyQualifiedName();
     }
     sort($fqns);
     foreach ($fqns as $name) {
         $file->addFullyQualifiedName(new FullyQualifiedName($name));
     }
     $file->setStructure($contract);
     $this->filesystem->mkdir($fileDir, 0755);
     $this->filesystem->dumpFile($filePath, Build::prettyPrinter()->generateCode($file), 0755);
     return $this;
 }