{"action":"created","issue":{"url":"https://api.github.com/repos/Jiro-Commerce/Product/issues/5","labels_url":"https://api.github.com/repos/Jiro-Commerce/Product/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/Jiro-Commerce/Product/issues/5/comments","events_url":"https://api.github.com/repos/Jiro-Commerce/Product/issues/5/events","html_url":"https://github.com/Jiro-Commerce/Product/issues/5","id":56899464,"number":5,"title":"[0.1.0] Product Builder.","user":{"login":"andrewmclagan","id":1073259,"avatar_url":"https://avatars.githubusercontent.com/u/1073259?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewmclagan","html_url":"https://github.com/andrewmclagan","followers_url":"https://api.github.com/users/andrewmclagan/followers","following_url":"https://api.github.com/users/andrewmclagan/following{/other_user}","gists_url":"https://api.github.com/users/andrewmclagan/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewmclagan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewmclagan/subscriptions","organizations_url":"https://api.github.com/users/andrewmclagan/orgs","repos_url":"https://api.github.com/users/andrewmclagan/repos","events_url":"https://api.github.com/users/andrewmclagan/events{/privacy}","received_events_url":"https://api.github.com/users/andrewmclagan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Jiro-Commerce/Product/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-02-07T06:09:18Z","updated_at":"2015-02-09T01:42:50Z","closed_at":null,"body":"Have you tought of a way how a developer could switch between ORMs?\r\nI made a quick draft of the builder:\r\n```php\r\n<?php namespace Jiro\\Product\\Builder;\r\n\r\nuse Jiro\\Product\\RepositoryInterface as ProductRepository;\r\nuse Jiro\\Property\\RepositoryInterface as PropertyRepository;\r\n\r\nclass ProductBuilder implements ProductBuilderInterface {\r\n\r\n\t/**\r\n     * Currently built product.\r\n     *\r\n     * @var ProductInterface\r\n     */\r\n    protected $product;\r\n\t\r\n\t/**\r\n     * Product repository.\r\n     *\r\n     * @var ProductRepositoryInterface\r\n     */\r\n    protected $productRepository;\r\n\r\n    /**\r\n     * Property repository.\r\n     *\r\n     * @var PropertyInterface\r\n     */\r\n    protected $propertyRepository;\r\n\r\n\tpublic function __construct(ProductRepository $productRepository, PropertyRepository $propertyRepository)\r\n\t{\r\n\t\t$this->productRepository = $productRepository;\r\n        $this->propertyRepository = $propertyRepository;\r\n\t}\r\n\t\r\n\t/**\r\n     * {@inheritdoc}\r\n     */\r\n    public function __call($method, $arguments)\r\n    {\r\n        if (!method_exists($this->product, $method)) {\r\n            throw new \\BadMethodCallException(sprintf('Product has no \"%s()\" method.', $method));\r\n        }\r\n\r\n        call_user_func_array([$this->product, $method], $arguments);\r\n\r\n        return $this;\r\n    }\r\n\t\r\n\t/**\r\n     * {@inheritdoc}\r\n     */\r\n    public function create($name)\r\n    {\r\n        $this->product = $this->productRepository->createNew();\r\n        $this->product->setName($name);\r\n\r\n        return $this;\r\n    }\r\n\t\r\n\t/**\r\n     * {@inheritdoc}\r\n     */\r\n\tpublic function addProperty($name, $value, $presentation = null)\r\n    {\r\n        $property = $this->propertyRepository->findByName($name);\r\n\r\n        if($property === null)\r\n        {\r\n            $property = $this->propertyRepository->createNew();\r\n            $property->setName($name);\r\n            $property->setValue($value);\r\n            $property->setPresentation($presentation);\r\n\r\n            $this->product->addProperty($property);\r\n        }\r\n\r\n        return $this;\r\n    }\r\n\t\r\n\t/**\r\n     * {@inheritdoc}\r\n     */\r\n    public function save()\r\n    {\r\n        $this->productRepository->save($this->product);\r\n\r\n        return $this->product;\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/Jiro-Commerce/Product/issues/comments/73446338","html_url":"https://github.com/Jiro-Commerce/Product/issues/5#issuecomment-73446338","issue_url":"https://api.github.com/repos/Jiro-Commerce/Product/issues/5","id":73446338,"user":{"login":"andrewmclagan","id":1073259,"avatar_url":"https://avatars.githubusercontent.com/u/1073259?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewmclagan","html_url":"https://github.com/andrewmclagan","followers_url":"https://api.github.com/users/andrewmclagan/followers","following_url":"https://api.github.com/users/andrewmclagan/following{/other_user}","gists_url":"https://api.github.com/users/andrewmclagan/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewmclagan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewmclagan/subscriptions","organizations_url":"https://api.github.com/users/andrewmclagan/orgs","repos_url":"https://api.github.com/users/andrewmclagan/repos","events_url":"https://api.github.com/users/andrewmclagan/events{/privacy}","received_events_url":"https://api.github.com/users/andrewmclagan/received_events","type":"User","site_admin":false},"created_at":"2015-02-09T01:42:50Z","updated_at":"2015-02-09T01:42:50Z","body":"Testing is a little complicated. Although not that bad. I will explain:\n\nLaravel uses Eloquent ORM which follows the active record pattern. Active record ORMs are great, easy to use and understand. Although one drawback is they couple the business objects (entities) to the persistence layer. In active record your entities ARE your persistence layer. Therefore you can't really test then with unit tests in isolation: how can you isolate things that are coupled? \n\nTherefore we need to do integration testing: testing in an i integrated system. We can use phpunit to do this, we just need to create an instance of a Laravel application and database to work with. So in each test we do this and setup an in memory SQLite database. Its all done automatically through the 'support\\testing\\DbTestCase' I setup. \n\nI have written the tests with behavioural wording, such as 'it_should_accept_new_variation()' . they are not passing science the structural changes we made to the folders. Thats what I will work at next. Getting back to green!\n\nHope all that makes sense..."}}