Skip to content

Commit 2579407

Browse files
authored
Merge pull request #48 from netresearch/CI-251
Establish M2.4 compatibility
2 parents 32fb867 + a9746fc commit 2579407

32 files changed

+363
-273
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Install it into your Magento 2 project with composer:
3636
If you need a customer without specific data, this is all:
3737

3838
```php
39-
protected function setUp()
39+
protected function setUp(): void
4040
{
4141
$this->customerFixture = new CustomerFixture(
4242
CustomerBuilder::aCustomer()->build()
4343
);
4444
}
45-
protected function tearDown()
45+
protected function tearDown(): void
4646
{
4747
CustomerFixtureRollback::create()->execute($this->customerFixture);
4848
}
@@ -98,7 +98,7 @@ $this->customerFixture->login();
9898

9999

100100

101-
### Adresses
101+
### Addresses
102102

103103
Similar to the customer builder you can also configure the address builder with custom attributes:
104104

@@ -120,7 +120,7 @@ AddressBuilder::anAddress()
120120
Product fixtures work similar as customer fixtures:
121121

122122
```php
123-
protected function setUp()
123+
protected function setUp(): void
124124
{
125125
$this->productFixture = new ProductFixture(
126126
ProductBuilder::aSimpleProduct()
@@ -133,7 +133,7 @@ protected function setUp()
133133
->build()
134134
);
135135
}
136-
protected function tearDown()
136+
protected function tearDown(): void
137137
{
138138
ProductFixtureRollback::create()->execute($this->productFixture);
139139
}

composer.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,27 @@
3030
}
3131
],
3232
"require": {
33-
"php": "^7.0",
34-
"magento/framework": "^101.0|^102.0",
35-
"magento/zendframework1": "^1.12",
36-
"magento/module-catalog": "^101.0|^102.0|^103.0",
37-
"magento/module-customer": "^100.1|^101.0|^102.0",
38-
"magento/module-checkout": "^100.1",
39-
"magento/module-indexer": "^100.0",
33+
"php": "^7.1",
34+
"magento/framework": "^102.0|^103.0",
35+
"magento/zendframework1": "^1.14",
36+
"magento/module-catalog": "^103.0|^104.0",
37+
"magento/module-catalog-inventory": "^100.3",
38+
"magento/module-checkout": "^100.3",
39+
"magento/module-customer": "^102.0|^103.0",
40+
"magento/module-directory": "^100.3",
41+
"magento/module-indexer": "^100.3",
42+
"magento/module-payment": "^100.3",
43+
"magento/module-quote": "^101.1",
44+
"magento/module-sales": "^102.0|^103.0",
4045
"fzaninotto/faker": "^v1.9.0"
41-
4246
},
4347
"require-dev": {
44-
"phpunit/phpunit": "^5.0|^6.0",
48+
"ext-json": "*",
49+
"magento/module-store": "^101.0",
50+
"phpunit/phpunit": "^6.0|^9.0",
4551
"pds/skeleton": "^1.0",
46-
"phpro/grumphp": "^0.11.6",
47-
"phpstan/phpstan": "^0.8.0",
52+
"phpro/grumphp": "^0.13.0",
53+
"phpstan/phpstan": "^0.9.0",
4854
"squizlabs/php_codesniffer": "^3.0"
4955
}
5056
}

registration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
\Magento\Framework\Component\ComponentRegistrar::register(
34
\Magento\Framework\Component\ComponentRegistrar::MODULE,
45
'TddWizard_Fixtures',

src/Catalog/CategoryBuilder.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44

55
use Magento\Catalog\Api\CategoryLinkRepositoryInterface;
66
use Magento\Catalog\Api\CategoryRepositoryInterface;
7-
use Magento\Catalog\Model\Category;
8-
use \Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
97
use Magento\Catalog\Api\Data\CategoryInterface;
108
use Magento\Catalog\Api\Data\CategoryProductLinkInterface;
119
use Magento\Catalog\Api\Data\CategoryProductLinkInterfaceFactory;
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
1212
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
1314

1415
class CategoryBuilder
1516
{
16-
/**
17-
* @var CategoryInterface
18-
*/
19-
private $category;
20-
2117
/**
2218
* @var CategoryRepositoryInterface
2319
*/
@@ -38,10 +34,15 @@ class CategoryBuilder
3834
*/
3935
private $productLinkFactory;
4036

37+
/**
38+
* @var CategoryInterface|Category
39+
*/
40+
private $category;
41+
4142
/**
4243
* @var int[]
4344
*/
44-
private $skus = [];
45+
private $skus;
4546

4647
public function __construct(
4748
CategoryRepositoryInterface $categoryRepository,
@@ -54,15 +55,15 @@ public function __construct(
5455
$this->categoryRepository = $categoryRepository;
5556
$this->categoryResource = $categoryResource;
5657
$this->categoryLinkRepository = $categoryLinkRepository;
58+
$this->productLinkFactory = $productLinkFactory;
5759
$this->category = $category;
5860
$this->skus = $skus;
59-
$this->productLinkFactory = $productLinkFactory;
6061
}
6162

62-
public static function topLevelCategory(ObjectManagerInterface $objectManager = null) : CategoryBuilder
63+
public static function topLevelCategory(ObjectManagerInterface $objectManager = null): CategoryBuilder
6364
{
6465
if ($objectManager === null) {
65-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
66+
$objectManager = Bootstrap::getObjectManager();
6667
}
6768
/** @var CategoryInterface $category */
6869
$category = $objectManager->create(CategoryInterface::class);
@@ -84,10 +85,9 @@ public static function topLevelCategory(ObjectManagerInterface $objectManager =
8485
public static function childCategoryOf(
8586
CategoryFixture $parent,
8687
ObjectManagerInterface $objectManager = null
87-
): CategoryBuilder
88-
{
88+
): CategoryBuilder {
8989
if ($objectManager === null) {
90-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
90+
$objectManager = Bootstrap::getObjectManager();
9191
}
9292
/** @var CategoryInterface $category */
9393
$category = $objectManager->create(CategoryInterface::class);
@@ -112,35 +112,35 @@ public static function childCategoryOf(
112112
* @param string[] $skus
113113
* @return CategoryBuilder
114114
*/
115-
public function withProducts(array $skus) : CategoryBuilder
115+
public function withProducts(array $skus): CategoryBuilder
116116
{
117117
$builder = clone $this;
118118
$builder->skus = $skus;
119119
return $builder;
120120
}
121121

122-
public function withDescription(string $description) : CategoryBuilder
122+
public function withDescription(string $description): CategoryBuilder
123123
{
124124
$builder = clone $this;
125125
$builder->category->setCustomAttribute('description', $description);
126126
return $builder;
127127
}
128128

129-
public function withName(string $name) : CategoryBuilder
129+
public function withName(string $name): CategoryBuilder
130130
{
131131
$builder = clone $this;
132132
$builder->category->setName($name);
133133
return $builder;
134134
}
135135

136-
public function withUrlKey(string $urlKey) : CategoryBuilder
136+
public function withUrlKey(string $urlKey): CategoryBuilder
137137
{
138138
$builder = clone $this;
139139
$builder->category->setData('url_key', $urlKey);
140140
return $builder;
141141
}
142142

143-
public function withIsActive(bool $isActive) : CategoryBuilder
143+
public function withIsActive(bool $isActive): CategoryBuilder
144144
{
145145
$builder = clone $this;
146146
$builder->category->setIsActive($isActive);
@@ -152,7 +152,11 @@ public function __clone()
152152
$this->category = clone $this->category;
153153
}
154154

155-
public function build() : CategoryInterface
155+
/**
156+
* @return CategoryInterface
157+
* @throws \Exception
158+
*/
159+
public function build(): CategoryInterface
156160
{
157161
$builder = clone $this;
158162
if (!$builder->category->getData('url_key')) {
@@ -175,4 +179,4 @@ public function build() : CategoryInterface
175179
}
176180
return $builder->category;
177181
}
178-
}
182+
}

src/Catalog/CategoryFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public function __construct(CategoryInterface $category)
2525
$this->category = $category;
2626
}
2727

28-
public function getId() : int
28+
public function getId(): int
2929
{
3030
return $this->category->getId();
3131
}
3232

33-
public function getUrlKey() : string
33+
public function getUrlKey(): string
3434
{
3535
/** @var Category $category */
3636
$category = $this->category;

src/Catalog/CategoryFixtureRollback.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
namespace TddWizard\Fixtures\Catalog;
44

55
use Magento\Catalog\Api\CategoryRepositoryInterface;
6+
use Magento\Framework\Exception\LocalizedException;
67
use Magento\Framework\ObjectManagerInterface;
78
use Magento\Framework\Registry;
9+
use Magento\TestFramework\Helper\Bootstrap;
810

911
class CategoryFixtureRollback
1012
{
1113
/**
1214
* @var Registry
1315
*/
1416
private $registry;
17+
1518
/**
1619
* @var CategoryRepositoryInterface
1720
*/
@@ -23,18 +26,22 @@ public function __construct(Registry $registry, CategoryRepositoryInterface $cat
2326
$this->categoryRepository = $categoryRepository;
2427
}
2528

26-
public static function create(ObjectManagerInterface $objectManager = null)
29+
public static function create(ObjectManagerInterface $objectManager = null): CategoryFixtureRollback
2730
{
2831
if ($objectManager === null) {
29-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
32+
$objectManager = Bootstrap::getObjectManager();
3033
}
3134
return new self(
3235
$objectManager->get(Registry::class),
3336
$objectManager->get(CategoryRepositoryInterface::class)
3437
);
3538
}
3639

37-
public function execute(CategoryFixture ...$categoryFixtures)
40+
/**
41+
* @param CategoryFixture ...$categoryFixtures
42+
* @throws LocalizedException
43+
*/
44+
public function execute(CategoryFixture ...$categoryFixtures): void
3845
{
3946
$this->registry->unregister('isSecureArea');
4047
$this->registry->register('isSecureArea', true);

src/Catalog/FulltextIndex.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ public function __construct(IndexerFactory $indexerFactory)
2525
$this->indexerFactory = $indexerFactory;
2626
}
2727

28-
public static function ensureTablesAreCreated()
28+
/**
29+
* @throws \Throwable
30+
*/
31+
public static function ensureTablesAreCreated(): void
2932
{
3033
if (!self::$created) {
3134
(new self(Bootstrap::getObjectManager()->create(IndexerFactory::class)))->reindex();
3235
}
3336
}
3437

35-
public function reindex()
38+
/**
39+
* @throws \Throwable
40+
*/
41+
public function reindex(): void
3642
{
37-
/** @var \Magento\Indexer\Model\Indexer $indexer */
3843
$indexer = $this->indexerFactory->create();
3944
$indexer->load('catalogsearch_fulltext');
4045
$indexer->reindexAll();
4146
}
42-
}
47+
}

src/Catalog/IndexFailed.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace TddWizard\Fixtures\Catalog;
@@ -23,7 +24,9 @@ public static function becauseInitiallyTriggeredInTransaction(\Exception $previo
2324
*/
2425
2526
TXT
26-
, 0, $previous
27+
,
28+
0,
29+
$previous
2730
);
2831
}
29-
}
32+
}

0 commit comments

Comments
 (0)