public function beforeTestMethod($method) { $fooMetadata = new ClassMetadata('foo', 'Acme\\Foo', ''); $mapping = new Mapping('/v1'); $mapping->setMapping([$fooMetadata]); $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $this->sdk = new \mock\Mapado\RestClientSdk\SdkClient(); $this->calling($this->sdk)->getMapping = $mapping; }
/** * testGetRepository * * @access public * @return void */ public function testGetRepository() { $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $restClient = new \mock\Mapado\RestClientSdk\RestClient(); $this->mockGenerator->unshuntParentClassCalls(); $mapping = new RestMapping(); $mapping->setMapping([new ClassMetadata('orders', 'Mapado\\RestClientSdk\\Tests\\Model\\Model', 'Mapado\\RestClientSdk\\Tests\\Model\\ModelRepository')]); $serializer = new Serializer($mapping); $this->given($testedInstance = $this->newTestedInstance($restClient, $mapping, $serializer))->then->object($testedInstance->getRestClient())->isIdenticalTo($restClient)->then->object($testedInstance->getMapping())->isIdenticalTo($mapping)->then->object($testedInstance->getSerializer())->isIdenticalTo($serializer)->then->object($testedInstance->getRepository('Mapado\\RestClientSdk\\Tests\\Model\\Model'))->isInstanceOf('Mapado\\RestClientSdk\\Tests\\Model\\ModelRepository')->object($testedInstance->getRepository('orders'))->isInstanceOf('Mapado\\RestClientSdk\\Tests\\Model\\ModelRepository')->exception(function () use($testedInstance) { $testedInstance->getRepository('foo'); })->isInstanceOf('Mapado\\RestClientSdk\\Exception\\MappingException'); }
public function testFindOneByObject() { $mapping = new Mapping('v12'); $mapping->setMapping([new ClassMetadata('carts', 'Mapado\\RestClientSdk\\Tests\\Model\\Cart', 'mock\\Mapado\\RestClientSdk\\EntityRepository'), new ClassMetadata('cart_items', 'Mapado\\RestClientSdk\\Tests\\Model\\CartItem', 'mock\\Mapado\\RestClientSdk\\EntityRepository')]); $this->calling($this->mockedSdk)->getMapping = $mapping; $this->calling($this->mockedRestClient)->get = []; $cartItemRepository = new \mock\Mapado\RestClientSdk\EntityRepository($this->mockedSdk, $this->mockedRestClient, 'Mapado\\RestClientSdk\\Tests\\Model\\CartItem'); $cart = new \Mapado\RestClientSdk\Tests\Model\Cart(); $cart->setId(1); $this->given($cart = new \Mapado\RestClientSdk\Tests\Model\Cart())->and($cart->setId(1))->if($cartItemRepository->findOneByCart($cart))->then->mock($this->mockedRestClient)->call('get')->withArguments('v12/cart_items?cart=1')->once()->given($cart = new \mock\stdClass())->if($cartItemRepository->findOneByCart($cart))->then->mock($this->mockedRestClient)->call('get')->withArguments('v12/cart_items?')->once(); }
/** * getMapping * * @access private * @return Mapping */ private function getMapping() { $cartMetadata = new ClassMetadata('carts', 'Mapado\\RestClientSdk\\Tests\\Model\\Cart', ''); $cartMetadata->setAttributeList([new Attribute('id', 'string', true), new Attribute('status'), new Attribute('clientPhoneNumber', 'phone_number'), new Attribute('createdAt', 'datetime'), new Attribute('cartItemList'), new Attribute('order')]); $cartMetadata->setRelationList([new Relation('cartItemList', Relation::ONE_TO_MANY, 'Mapado\\RestClientSdk\\Tests\\Model\\CartItem'), new Relation('order', Relation::MANY_TO_ONE, 'Mapado\\RestClientSdk\\Tests\\Model\\Order')]); $cartItemMetadata = new ClassMetadata('cart_items', 'Mapado\\RestClientSdk\\Tests\\Model\\CartItem', ''); $cartItemMetadata->setRelationList([new Relation('cart', Relation::MANY_TO_ONE, 'Mapado\\RestClientSdk\\Tests\\Model\\Cart'), new Relation('product', Relation::MANY_TO_ONE, 'Mapado\\RestClientSdk\\Tests\\Model\\Product'), new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\\RestClientSdk\\Tests\\Model\\CartItemDetail')]); $cartItemMetadata->setAttributeList([new Attribute('id', 'string', true), new Attribute('amount'), new Attribute('createdAt', 'datetime'), new Attribute('data'), new Attribute('cart'), new Attribute('product'), new Attribute('cartItemDetailList')]); $productMetadata = new ClassMetadata('products', 'Mapado\\RestClientSdk\\Tests\\Model\\Product', ''); $productMetadata->setAttributeList([new Attribute('id', 'string', true), new Attribute('value'), new Attribute('currency')]); $cartItemDetailMetadata = new ClassMetadata('cart_item_details', 'Mapado\\RestClientSdk\\Tests\\Model\\CartItemDetail', ''); $cartItemDetailMetadata->setRelationList([new Relation('cartItem', Relation::MANY_TO_ONE, 'Mapado\\RestClientSdk\\Tests\\Model\\CartItem')]); $cartItemDetailMetadata->setAttributeList([new Attribute('id', 'string', true), new Attribute('name'), new Attribute('cartItem')]); $mapping = new Mapping('/v1'); $mapping->setMapping([$cartMetadata, $cartItemMetadata, $cartItemDetailMetadata, $productMetadata]); return $mapping; }