Skip to content

Commit 78107aa

Browse files
authored
Use iterable to allow generators (#53)
* use iterable to allow generators * ci/cd: bump action versions * tests: update phpunit and faker tests: update phpunit and faker tests: use max 10 version * phpcs: update min version * phpcs: ignore env to works with php > 8.0
1 parent a3358db commit 78107aa

File tree

7 files changed

+46
-37
lines changed

7 files changed

+46
-37
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ on:
99
jobs:
1010
tests:
1111
name: PHPUnit PHP ${{ matrix.php }}
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313
strategy:
1414
matrix:
1515
php:
16-
- '5.6'
1716
- '7.1'
17+
- '8.4'
1818
fail-fast: false
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
2222

2323
- name: Setup PHP
2424
uses: shivammathur/setup-php@v2
@@ -34,7 +34,7 @@ jobs:
3434
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
3535

3636
- name: Cache dependencies
37-
uses: actions/cache@v2
37+
uses: actions/cache@v4
3838
with:
3939
path: ${{ steps.composer-cache.outputs.dir }}
4040
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
@@ -51,7 +51,7 @@ jobs:
5151
run: ./vendor/bin/phpcs
5252

5353
- name: Run CS Fixer
54-
run: ./vendor/bin/php-cs-fixer fix --config=./.php_cs -v --dry-run
54+
run: PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix --config=./.php_cs -v --dry-run
5555

5656
- name: Run tests
5757
run: ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
"issues": "https://github.com/Bukashk0zzz/YmlGenerator/issues"
1818
},
1919
"require": {
20-
"php": ">=5.6.1",
20+
"php": ">=7.1",
2121
"ext-simplexml": "*",
2222
"ext-xmlwriter": "*"
2323
},
2424
"require-dev": {
2525
"ext-dom": "*",
26-
"phpunit/phpunit": "^5.0",
27-
"fzaninotto/faker": "^1.6",
26+
"phpunit/phpunit": ">=7.0,<10",
2827
"friendsofphp/php-cs-fixer": "^2.3",
2928
"escapestudios/symfony2-coding-standard": "^3.0",
3029
"phpcompatibility/php-compatibility": "^9.0",
31-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
30+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
31+
"fakerphp/faker": "v1.20.0"
3232
},
3333
"autoload": {
3434
"psr-4": {

phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<exclude name="Symfony.ControlStructure.YodaConditions.Invalid"/>
1010
</rule>
1111

12-
<config name="testVersion" value="5.6-"/>
12+
<config name="testVersion" value="7.1-"/>
1313

1414
<arg name="colors"/>
1515
<arg name="encoding" value="utf-8"/>

phpunit.xml.dist

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="vendor/autoload.php"
1312
>
1413

@@ -18,13 +17,13 @@
1817
</testsuite>
1918
</testsuites>
2019

21-
<filter>
22-
<whitelist>
20+
<coverage>
21+
<include>
2322
<directory>./</directory>
24-
<exclude>
25-
<directory>./tests</directory>
26-
<directory>./vendor</directory>
27-
</exclude>
28-
</whitelist>
29-
</filter>
23+
</include>
24+
<exclude>
25+
<directory>./tests</directory>
26+
<directory>./vendor</directory>
27+
</exclude>
28+
</coverage>
3029
</phpunit>

src/Generator.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public function __construct($settings = null)
7070

7171
/**
7272
* @param ShopInfo $shopInfo
73-
* @param array $currencies
74-
* @param array $categories
75-
* @param array $offers
76-
* @param array $deliveries
73+
* @param iterable $currencies
74+
* @param iterable $categories
75+
* @param iterable $offers
76+
* @param iterable $deliveries
7777
*
7878
* @return bool
7979
*/
80-
public function generate(ShopInfo $shopInfo, array $currencies, array $categories, array $offers, array $deliveries = [])
80+
public function generate(ShopInfo $shopInfo, iterable $currencies, iterable $categories, iterable $offers, iterable $deliveries = [])
8181
{
8282
try {
8383
$this->addHeader();
@@ -229,9 +229,9 @@ protected function addOffer(OfferInterface $offer)
229229
/**
230230
* Adds <currencies> element. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#currencies)
231231
*
232-
* @param array $currencies
232+
* @param iterable $currencies
233233
*/
234-
private function addCurrencies(array $currencies)
234+
private function addCurrencies(iterable $currencies)
235235
{
236236
$this->writer->startElement('currencies');
237237

@@ -248,9 +248,9 @@ private function addCurrencies(array $currencies)
248248
/**
249249
* Adds <categories> element. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#categories)
250250
*
251-
* @param array $categories
251+
* @param iterable $categories
252252
*/
253-
private function addCategories(array $categories)
253+
private function addCategories(iterable $categories)
254254
{
255255
$this->writer->startElement('categories');
256256

@@ -267,9 +267,9 @@ private function addCategories(array $categories)
267267
/**
268268
* Adds <delivery-option> element. (See https://yandex.ru/support/partnermarket/elements/delivery-options.xml)
269269
*
270-
* @param array $deliveries
270+
* @param iterable $deliveries
271271
*/
272-
private function addDeliveries(array $deliveries)
272+
private function addDeliveries(iterable $deliveries)
273273
{
274274
$this->writer->startElement('delivery-options');
275275

@@ -286,9 +286,9 @@ private function addDeliveries(array $deliveries)
286286
/**
287287
* Adds <offers> element. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#offers)
288288
*
289-
* @param array $offers
289+
* @param iterable $offers
290290
*/
291-
private function addOffers(array $offers)
291+
private function addOffers(iterable $offers)
292292
{
293293
$this->writer->startElement('offers');
294294

tests/AbstractGeneratorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
use Bukashk0zzz\YmlGenerator\Model\ShopInfo;
1919
use Bukashk0zzz\YmlGenerator\Settings;
2020
use Faker\Factory as Faker;
21+
use PHPUnit\Framework\TestCase;
2122

2223
/**
2324
* Abstract Generator test
2425
*/
25-
abstract class AbstractGeneratorTest extends \PHPUnit_Framework_TestCase
26+
abstract class AbstractGeneratorTest extends TestCase
2627
{
2728
/**
2829
* @var \Faker\Generator
@@ -62,7 +63,7 @@ abstract class AbstractGeneratorTest extends \PHPUnit_Framework_TestCase
6263
/**
6364
* Test setup
6465
*/
65-
protected function setUp()
66+
protected function setUp(): void
6667
{
6768
$this->faker = Faker::create();
6869

tests/GeneratorTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,36 @@
1414
use Bukashk0zzz\YmlGenerator\Generator;
1515
use Bukashk0zzz\YmlGenerator\Model\ShopInfo;
1616
use Bukashk0zzz\YmlGenerator\Settings;
17+
use PHPUnit\Framework\TestCase;
1718

1819
/**
1920
* Generator test
2021
*/
21-
class GeneratorTest extends \PHPUnit_Framework_TestCase
22+
class GeneratorTest extends TestCase
2223
{
2324
/**
24-
* @expectedException \RuntimeException
25+
* Test exception if no output file used
2526
*/
2627
public function testExceptionForIncompatibleAnnotations()
2728
{
29+
// PHP 8.0+ throws ValueError
30+
if (\PHP_VERSION > 8.0) {
31+
$this->expectException(\ValueError::class);
32+
} else {
33+
$this->expectException(\RuntimeException::class);
34+
}
35+
2836
(new Generator((new Settings())->setOutputFile('')))
2937
->generate(new ShopInfo(), [], [], [])
3038
;
3139
}
3240

3341
/**
34-
* @expectedException \LogicException
42+
* Test exception if no output file used
3543
*/
3644
public function testExceptionIfManyDestinationUsed()
3745
{
46+
$this->expectException(\LogicException::class);
3847
$settings = (new Settings())
3948
->setOutputFile('')
4049
->setReturnResultYMLString(true)

0 commit comments

Comments
 (0)