From 54bc212acac31c792ae4ca44721172462e8bc193 Mon Sep 17 00:00:00 2001 From: "michael.koltan@oxid-esales.com" Date: Wed, 24 Apr 2019 11:50:29 +0200 Subject: [PATCH] Make module backward compatible for compilation 6.1.3 --- services.yaml | 19 +++++--- tests/Integration/Dao/CategoryDaoTest.php | 56 +++++++++++++++++------ 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/services.yaml b/services.yaml index fb5cc3a..8e267bc 100644 --- a/services.yaml +++ b/services.yaml @@ -1,22 +1,29 @@ services: - _defaults: - public: false - autowire: true - OxidEsales\GraphQl\Sample\Dao\CategoryDaoInterface: class: OxidEsales\GraphQl\Sample\Dao\CategoryDao + public: false + autowire: true OxidEsales\GraphQl\Sample\Type\ObjectType\CategoryType: class: OxidEsales\GraphQl\Sample\Type\ObjectType\CategoryType + public: false + autowire: true OxidEsales\GraphQl\Sample\Type\Provider\CategoryProvider: class: OxidEsales\GraphQl\Sample\Type\Provider\CategoryProvider - tags: ['graphql_query_provider', 'graphql_mutation_provider'] + public: false + autowire: true + tags: + - {name: 'graphql_query_provider'} + - {name: 'graphql_mutation_provider'} OxidEsales\GraphQl\Sample\Service\CategoryPermissionsProvider: class: OxidEsales\GraphQl\Service\PermissionsProvider + public: false + autowire: true calls: - ['addPermission', ['admin', 'mayaddcategory']] - ['addPermission', ['shopadmin', 'mayaddcategory']] - tags: ['graphql_permissions_provider'] + tags: + - {name: 'graphql_permissions_provider'} diff --git a/tests/Integration/Dao/CategoryDaoTest.php b/tests/Integration/Dao/CategoryDaoTest.php index 0abf367..13553bd 100644 --- a/tests/Integration/Dao/CategoryDaoTest.php +++ b/tests/Integration/Dao/CategoryDaoTest.php @@ -8,57 +8,85 @@ namespace OxidEsales\GraphQl\Sample\Tests\Integration\Dao; - -use OxidEsales\EshopCommunity\Tests\Integration\Internal\TestContainerFactory; +use OxidEsales\GraphQl\Exception\ObjectNotFoundException; use OxidEsales\GraphQl\Sample\Dao\CategoryDao; use OxidEsales\GraphQl\Sample\Dao\CategoryDaoInterface; -use PHPUnit\Framework\TestCase; +use OxidEsales\GraphQl\Tests\Integration\ContainerTrait; -class CategoryDaoTest extends TestCase +class CategoryDaoTest extends \PHPUnit_Framework_TestCase { + use ContainerTrait; /** @var CategoryDao $categoryDao */ private $categoryDao; + /** @var string $categoryIdRoot */ + private $categoryIdRoot; + + /** @var string $categoryIdSub1 */ + private $categoryIdSub1; + + /** @var string $categoryIdSub2 */ + private $categoryIdSub2; + public function setUp() { - $containerFactory = new TestContainerFactory(); - $container = $containerFactory->create(); + $container = $this->createUncompiledContainer(); $container->compile(); $this->categoryDao = $container->get(CategoryDaoInterface::class); + + $this->categoryIdRoot = $this->categoryDao->addCategory(['Test deutsch', 'Test english'], 1); + $this->categoryIdSub1 = $this->categoryDao->addCategory(['Unterkategorie 1', 'sub category 1'], 1, + $this->categoryIdRoot); + $this->categoryIdSub2 = $this->categoryDao->addCategory(['Unterkategorie 2', 'sub category 2'], 1, + $this->categoryIdRoot); } public function testGetCategory() { - $category = $this->categoryDao->getCategory('30e44ab834ea42417.86131097', 'de', 1); - $this->assertEquals('30e44ab834ea42417.86131097', $category->getId()); - $this->assertEquals('Für Ihn', $category->getName()); + $category = $this->categoryDao->getCategory($this->categoryIdRoot, 'de', 1); + $this->assertEquals($this->categoryIdRoot, $category->getId()); + $this->assertEquals('Test deutsch', $category->getName()); } public function testGetCategoryOtherShop() { - $this->expectExceptionMessage('Category with id "30e44ab834ea42417.86131097" not found.'); - $this->categoryDao->getCategory('30e44ab834ea42417.86131097', 'de', 2); + $this->setExpectedException(ObjectNotFoundException::class, 'Category with id "'. $this->categoryIdRoot . + '" not found.'); + $this->categoryDao->getCategory($this->categoryIdRoot, 'de', 2); } public function testGetCategoryWithWrongId() { - $this->expectException(\Exception::class); + $this->setExpectedException(\Exception::class); $this->categoryDao->getCategory('somenonexistingid', 'de', 1); } public function testGetRootCategories() { $rootCategories = $this->categoryDao->getCategories('de', 1); - $this->assertEquals(7, sizeof($rootCategories)); + $found = false; + foreach ($rootCategories as $rootCategory) { + /** @var \OxidEsales\GraphQl\Sample\DataObject\Category $rootCategory */ + if ($rootCategory->getId() == $this->categoryIdRoot) { + $found = true; + } + if ($rootCategory->getId() == $this->categoryIdSub1) { + $this->fail('This should not be in the list of root categories.'); + } + if ($rootCategory->getId() == $this->categoryIdSub2) { + $this->fail('This should not be in the list of root categories.'); + } + } + $this->assertTrue($found); } public function testGetSubCategories() { - $subCategories = $this->categoryDao->getCategories('de', 1, '30e44ab834ea42417.86131097'); + $subCategories = $this->categoryDao->getCategories('de', 1, $this->categoryIdRoot); $this->assertEquals(2, sizeof($subCategories)); }