Skip to content

Commit

Permalink
5 Add-CI + fix test to be able to support difference between PHP 7.2 …
Browse files Browse the repository at this point in the history
…and 7.3 (leomarquine#33)

* 5-add-ci

* Test

* Fix test
  • Loading branch information
ecourtial authored May 25, 2020
1 parent 47089e4 commit 9c077a1
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 43 deletions.
181 changes: 181 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
version: '2.1'
executors:
php7-2:
docker:
- image: php:7.2-alpine
working_directory: ~/repo
php7-3:
docker:
- image: php:7.3-alpine
working_directory: ~/repo
php7-4:
docker:
- image: php:7.4-alpine
working_directory: ~/repo

jobs:
# The complete list : all in the minimum PHP version supported.
composer7-2:
executor: php7-2
steps:
- run:
name: Install alpine requirements for checkout
command: apk add git openssh-client curl
- checkout
- restore_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
- run:
name: composer
command: |
if [[ ! -f vendor/autoload.php ]]; then
curl https://getcomposer.org/composer-stable.phar --location --silent --output /usr/bin/composer; \
chmod +x /usr/bin/composer; \
composer install --no-progress --no-interaction; \
fi
- save_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
paths:
- ./vendor
- persist_to_workspace:
root: .
paths:
- vendor

phpcs7-2:
executor: php7-2
steps:
- checkout
- attach_workspace:
at: .
- run:
name: phpcs
command: vendor/bin/phpcs

phpcsfixer7-2:
executor: php7-2
steps:
- checkout
- attach_workspace:
at: .
- run:
name: phpcsfixer
command: vendor/bin/php-cs-fixer fix --dry-run --allow-risky=yes

phpstan7-2:
executor: php7-2
steps:
- checkout
- attach_workspace:
at: .
- run:
name: phpstan
command: vendor/bin/phpstan analyse

phpunit7-2:
executor: php7-2
steps:
- checkout
- attach_workspace:
at: .
- run:
name: phpunit
command: vendor/bin/phpunit --testdox

# Now we repeat the basics for each PHP version. Composer + PHPUNIT
composer7-3:
executor: php7-3
steps:
- run:
name: Install alpine requirements for checkout
command: apk add git openssh-client curl
- checkout
- restore_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
- run:
name: composer
command: |
if [[ ! -f vendor/autoload.php ]]; then
curl https://getcomposer.org/composer-stable.phar --location --silent --output /usr/bin/composer; \
chmod +x /usr/bin/composer; \
composer install --no-progress --no-interaction; \
fi
- save_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
paths:
- ./vendor
- persist_to_workspace:
root: .
paths:
- vendor

phpunit7-3:
executor: php7-3
steps:
- checkout
- attach_workspace:
at: .
- run:
name: phpunit
command: vendor/bin/phpunit --testdox

composer7-4:
executor: php7-4
steps:
- run:
name: Install alpine requirements for checkout
command: apk add git openssh-client curl
- checkout
- restore_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
- run:
name: composer
command: |
if [[ ! -f vendor/autoload.php ]]; then
curl https://getcomposer.org/composer-stable.phar --location --silent --output /usr/bin/composer; \
chmod +x /usr/bin/composer; \
composer install --no-progress --no-interaction; \
fi
- save_cache:
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
paths:
- ./vendor
- persist_to_workspace:
root: .
paths:
- vendor

phpunit7-4:
executor: php7-4
steps:
- checkout
- attach_workspace:
at: .
- run:
name: phpunit
command: vendor/bin/phpunit --testdox

workflows:
version: '2.1'
Code quality:
jobs:
- composer7-2
- composer7-3
- composer7-4
- phpcs7-2:
requires:
- composer7-2
- phpcsfixer7-2:
requires:
- composer7-2
- phpstan7-2:
requires:
- composer7-2
- phpunit7-2:
requires:
- composer7-2
- phpunit7-3:
requires:
- composer7-3
- phpunit7-4:
requires:
- composer7-4
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"infection/infection": "^0.16.2",
"infection/infection": "^0.15.3",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.18",
"phpstan/phpstan-deprecation-rules": "^0.12.2",
Expand Down
8 changes: 2 additions & 6 deletions src/Traits/FilePathTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* @author Wizacha DevTeam <[email protected]>
* @copyright Copyright (c) Wizacha
* @copyright Copyright (c) Leonardo Marquine
* @license MIT
*/

Expand All @@ -17,7 +16,7 @@ trait FilePathTrait
{
/**
* Check if path dirname exist,
* recursivly create dir path if not
* recursively create dir path if not
*
* @throws IoException
*/
Expand All @@ -31,10 +30,7 @@ protected function checkOrCreateDir(string $fileUri): bool

$isCreated = @\mkdir($dirName, 0755, true);
if (false === $isCreated) {
throw new IoException(
"Cannot create path: $dirName",
1
);
throw new IoException("Cannot create path: $dirName", 1);
}

return $isCreated;
Expand Down
6 changes: 0 additions & 6 deletions tests/Extractors/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ public function filtering_columns_with_incomplete_line()
try {
$count = 1;
foreach ($extractor->extract() as $row) {
if (3 === $count) {
static::fail('Since we asked more columns than available, an exception was expected');
}
$count++;
}
} catch (\Throwable $exception) {
Expand Down Expand Up @@ -146,9 +143,6 @@ public function filtering_columns_with_unavailable_field()
try {
$count = 1;
foreach ($extractor->extract() as $row) {
if (3 === $count) {
static::fail('Since we asked a field not available, an exception was expected');
}
$count++;
}
} catch (\Throwable $exception) {
Expand Down
1 change: 0 additions & 1 deletion tests/Loaders/CsvLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Tests\Loaders;

use Tests\TestCase;
use Wizaplace\Etl\Exception\IoException;
use Wizaplace\Etl\Loaders\CsvLoader;
use Wizaplace\Etl\Row;

Expand Down
26 changes: 1 addition & 25 deletions tests/Traits/FilePathTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class FilePathTraitTest extends TestCase

public function setUp(): void
{
$this->fakeLoader = new class ()
{
$this->fakeLoader = new class() {
use FilePathTrait;

public function input(string $filePath)
Expand Down Expand Up @@ -57,27 +56,4 @@ public function illegal_path_trigger_exception()

$this->fakeLoader->input($filePath);
}

/** @test */
public function unwritable_path_trigger_exception()
{
// make a forbidden folder
$basePath = '/tmp/forbidden';
if (is_dir($basePath)) {
rmdir($basePath); // remove if any previous
}
mkdir($basePath, 0000);

$filePath = "$basePath/stuff/file";

static::expectException(IoException::class);
static::expectExceptionMessage(
sprintf(
'Cannot create path: %s',
dirname($filePath)
)
);

$this->fakeLoader->input($filePath);
}
}
16 changes: 12 additions & 4 deletions tests/Transformers/ConvertCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ public function uppercase()
/** @test */
public function titlecase()
{
$expected = [
new Row(['id' => '1', 'name' => 'Jane Doe', 'email' => '[email protected]']),
new Row(['id' => '2', 'name' => 'John Doe', 'email' => '[email protected]']),
];
// @see https://www.php.net/manual/en/migration73.new-features.php
if (phpversion() < 7.3) {
$expected = [
new Row(['id' => '1', 'name' => 'Jane Doe', 'email' => '[email protected]']),
new Row(['id' => '2', 'name' => 'John Doe', 'email' => '[email protected]']),
];
} else {
$expected = [
new Row(['id' => '1', 'name' => 'Jane Doe', 'email' => '[email protected]']),
new Row(['id' => '2', 'name' => 'John Doe', 'email' => '[email protected]']),
];
}

$transformer = new ConvertCase();

Expand Down

0 comments on commit 9c077a1

Please sign in to comment.