Skip to content

Commit 382e944

Browse files
authored
Better travis config (#24)
* Better travis config * Code cleanup * Bugfixes * Updated dev requirements * Applied changes from StyleCI
1 parent a09b4a4 commit 382e944

File tree

6 files changed

+116
-105
lines changed

6 files changed

+116
-105
lines changed

.travis.yml

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,56 @@ branches:
99
- /^analysis-.*$/
1010
- /^patch-.*$/
1111

12-
php:
13-
- 5.5
14-
- 5.6
15-
- 7.0
16-
- 7.1
17-
1812
env:
1913
global:
2014
- TEST_COMMAND="composer test"
21-
matrix:
22-
- SYMFONY_VERSION=3.3.*
23-
- SYMFONY_VERSION=2.7.*
2415

2516
matrix:
26-
fast_finish: true
27-
include:
28-
- php: 5.5
29-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" SYMFONY_VERSION=2.8.*
30-
- php: hhvm
31-
dist: trusty
32-
env: SYMFONY_VERSION=2.8.*
33-
- php: 7.0
34-
env: SYMFONY_VERSION=2.8.*
35-
- php: 7.1
36-
env: SYMFONY_VERSION=3.4.*
37-
- php: 7.1
38-
env: SYMFONY_VERSION=4.0.*
39-
- php: 7.0
40-
env: SYMFONY_VERSION=3.0.*
41-
- php: 7.0
42-
env: SYMFONY_VERSION=3.1.*
43-
- php: 7.0
44-
env: SYMFONY_VERSION=3.2.*
17+
fast_finish: true
18+
include:
19+
# Test with lowest dependencies
20+
- php: 7.1
21+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
22+
- php: 5.5
23+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
24+
25+
# Test the latest stable release
26+
- php: 5.5
27+
- php: 5.6
28+
- php: 7.0
29+
- php: 7.1
30+
- php: 7.2
31+
env: COVERAGE=true TEST_COMMAND="composer test-ci"
32+
33+
# Force some major versions of Symfony
34+
- php: 7.2
35+
env: DEPENDENCIES="dunglas/symfony-lock:^2"
36+
- php: 7.2
37+
env: DEPENDENCIES="dunglas/symfony-lock:^3"
38+
- php: 7.2
39+
env: DEPENDENCIES="dunglas/symfony-lock:^4"
40+
41+
# Latest commit to master
42+
- php: 7.2
43+
env: STABILITY="dev"
44+
45+
allow_failures:
46+
# Dev-master is allowed to fail.
47+
- env: STABILITY="dev"
48+
49+
before_install:
50+
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
51+
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
52+
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
4553

4654
install:
47-
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
48-
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
55+
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
56+
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
57+
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
58+
- vendor/bin/simple-phpunit install
4959

5060
script:
61+
- composer validate --strict --no-check-lock
5162
- $TEST_COMMAND
5263

5364
after_success:

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"nyholm/nsa": "^1.1"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.2",
19-
"symfony/framework-bundle": "^2.7 || ^3.0 || ^4.0"
18+
"symfony/phpunit-bridge": "^3.4 || ^4.0",
19+
"symfony/framework-bundle": "^2.7.39 || ^3.0 || ^4.0"
2020
},
2121
"autoload": {
2222
"psr-4": {
@@ -29,10 +29,9 @@
2929
}
3030
},
3131
"scripts": {
32-
"test": "vendor/bin/phpunit",
33-
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
32+
"test": "vendor/bin/simple-phpunit",
33+
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
3434
},
35-
"minimum-stability": "dev",
3635
"extra": {
3736
"branch-alias": {
3837
"dev-master": "0.3-dev"

src/FileStorage.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
namespace Translation\SymfonyStorage;
1313

14-
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader as SymfonyTranslationLoader;
1514
use Symfony\Component\Translation\MessageCatalogue;
1615
use Symfony\Component\Translation\MessageCatalogueInterface;
17-
use Symfony\Component\Translation\Reader\TranslationReader;
18-
use Symfony\Component\Translation\Writer\TranslationWriter;
16+
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
1917
use Symfony\Component\Translation\Writer\TranslationWriterInterface;
2018
use Translation\Common\Model\Message;
2119
use Translation\Common\Storage;
@@ -29,14 +27,14 @@
2927
final class FileStorage implements Storage, TransferableStorage
3028
{
3129
/**
32-
* @var TranslationWriterInterface|LegacyTranslationWriter
30+
* @var TranslationWriterInterface
3331
*/
3432
private $writer;
3533

3634
/**
37-
* @var TranslationLoader|SymfonyTranslationLoader
35+
* @var TranslationReaderInterface
3836
*/
39-
private $loader;
37+
private $reader;
4038

4139
/**
4240
* @var array directory path
@@ -49,28 +47,26 @@ final class FileStorage implements Storage, TransferableStorage
4947
private $options;
5048

5149
/**
52-
* @var MessageCatalogue[] Fetched catalogies
50+
* @var MessageCatalogue[] Fetched catalogues
5351
*/
5452
private $catalogues;
5553

5654
/**
57-
* @param TranslationWriter $writer
58-
* @param SymfonyTranslationLoader|TranslationLoader|TranslationReader $loader
59-
* @param array $dir
60-
* @param array $options
55+
* @param TranslationWriterInterface $writer
56+
* @param TranslationReaderInterface $reader
57+
* @param array $dir
58+
* @param array $options
6159
*/
62-
public function __construct(TranslationWriter $writer, $loader, array $dir, array $options = [])
60+
public function __construct($writer, $reader, array $dir, array $options = [])
6361
{
64-
// Create a legacy writer which is a wrapper for TranslationWriter
62+
// Create a wrapper for legacy writer
6563
if (!$writer instanceof TranslationWriterInterface) {
6664
$writer = new LegacyTranslationWriter($writer);
6765
}
68-
// Create a legacy loader which is a wrapper for TranslationReader
69-
if ($loader instanceof TranslationReader) {
70-
$loader = new LegacyTranslationLoader($loader);
71-
}
72-
if (!$loader instanceof SymfonyTranslationLoader && !$loader instanceof TranslationLoader) {
73-
throw new \LogicException('Second parameter of FileStorage must be a Symfony translation loader or implement Translation\SymfonyStorage\TranslationLoader');
66+
67+
// Create a wrapper for legacy reader
68+
if (!$reader instanceof TranslationReaderInterface) {
69+
$reader = new LegacyTranslationReader($reader);
7470
}
7571

7672
if (empty($dir)) {
@@ -83,7 +79,7 @@ public function __construct(TranslationWriter $writer, $loader, array $dir, arra
8379
}
8480

8581
$this->writer = $writer;
86-
$this->loader = $loader;
82+
$this->reader = $reader;
8783
$this->dir = $dir;
8884
$this->options = $options;
8985
}
@@ -157,10 +153,10 @@ public function import(MessageCatalogueInterface $catalogue)
157153
/**
158154
* Save catalogue back to file.
159155
*
160-
* @param MessageCatalogue $catalogue
161-
* @param string $domain
156+
* @param MessageCatalogueInterface $catalogue
157+
* @param string $domain
162158
*/
163-
private function writeCatalogue(MessageCatalogue $catalogue, $locale, $domain)
159+
private function writeCatalogue(MessageCatalogueInterface $catalogue, $locale, $domain)
164160
{
165161
$resources = $catalogue->getResources();
166162
$options = $this->options;
@@ -209,7 +205,7 @@ private function loadCatalogue($locale, array $dirs)
209205
$currentCatalogue = new MessageCatalogue($locale);
210206
foreach ($dirs as $path) {
211207
if (is_dir($path)) {
212-
$this->loader->loadMessages($path, $currentCatalogue);
208+
$this->reader->read($path, $currentCatalogue);
213209
}
214210
}
215211

src/LegacyTranslationLoader.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/LegacyTranslationReader.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHP Translation package.
5+
*
6+
* (c) PHP Translation team <tobias.nyholm@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Translation\SymfonyStorage;
13+
14+
use Symfony\Component\Translation\MessageCatalogue;
15+
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader;
16+
17+
/**
18+
* This loader is just a wrapper for Symfony TranslationLoader
19+
* and provide a BC layer for Symfony 2.7 to 3.3.
20+
*
21+
* @author Victor Bocharsky <bocharsky.bw@gmail.com>
22+
*/
23+
final class LegacyTranslationReader // implements Symfony\Component\Translation\Reader\TranslationReaderInterface
24+
{
25+
/**
26+
* @var TranslationLoader
27+
*/
28+
private $loader;
29+
30+
public function __construct($loader)
31+
{
32+
if (!$loader instanceof TranslationLoader) {
33+
throw new \LogicException(sprintf('PHP-Translation/SymfonyStorage does not support a TranslationReader of type "%s".', get_class($loader)));
34+
}
35+
$this->loader = $loader;
36+
}
37+
38+
public function read($directory, MessageCatalogue $catalogue)
39+
{
40+
$this->loader->loadMessages($directory, $catalogue);
41+
}
42+
}

src/LegacyTranslationWriter.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
use Symfony\Component\Translation\Writer\TranslationWriter;
1616

1717
/**
18-
* This writer is just a legacy wrapper for Symfony TranslationWriter
19-
* and provide a BC layer for Symfony 4.
18+
* This writer is just a wrapper for Symfony TranslationWriter
19+
* and provide a BC layer for Symfony 2.7 to 3.3.
2020
*
2121
* @author Victor Bocharsky <bocharsky.bw@gmail.com>
2222
*/
23-
class LegacyTranslationWriter
23+
final class LegacyTranslationWriter // implements Symfony\Component\Translation\Writer\TranslationWriterInterface
2424
{
25-
/**
26-
* @var TranslationWriter
27-
*/
2825
private $writer;
2926

30-
public function __construct(TranslationWriter $writer)
27+
public function __construct($writer)
3128
{
29+
// If not Translation writer from sf 2.7 to 3.3
30+
if (!$writer instanceof TranslationWriter) {
31+
throw new \LogicException(sprintf('PHP-Translation/SymfonyStorage does not support a TranslationWriter of type "%s".', get_class($writer)));
32+
}
33+
3234
$this->writer = $writer;
3335
}
3436

0 commit comments

Comments
 (0)