diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..36e422d
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,63 @@
+name: Unit Tests
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ provide_php_versions_json:
+ runs-on: ubuntu-latest
+
+ steps:
+ # git clone + use PHP + composer install
+ - uses: actions/checkout@v2
+ - uses: shivammathur/setup-php@v2
+ with:
+ php-version: 8.0
+
+ - run: composer install --no-progress --ansi
+
+ - run: vendor/bin/easy-ci php-versions-json
+
+ - id: output_data
+ run: echo "::set-output name=matrix::$(vendor/bin/easy-ci php-versions-json)"
+
+ outputs:
+ matrix: ${{ steps.output_data.outputs.matrix }}
+
+ unit_tests:
+ needs: provide_php_versions_json
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ php: ${{ fromJson(needs.provide_php_versions_json.outputs.matrix) }}
+
+ name: PHP ${{ matrix.php }} tests
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ coverage: none
+
+ # composer install cache - https://github.com/ramsey/composer-install
+
+ - if: "matrix.php >= 8"
+ uses: "ramsey/composer-install@v1"
+ with:
+ composer-options: "--ignore-platform-req php"
+
+
+ - name: Run phplint - Syntax check
+ run: ./vendor/bin/phplint -c ci/phplint.yml lib
+ - name: Run phpcs - PSR2 check
+ run: ./vendor/bin/phpcs --standard=ci/phpbcs.xml lib
+ - name: Run PHPUnit tests
+ run: ./vendor/bin/phpunit test
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 978bdaf..835e142 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@ composer.lock
composer.phar
vendor/*
docker-compose.yml
+.phplint-cache
+.phpunit.result.cache
diff --git a/ci/phpbcs.xml b/ci/phpbcs.xml
new file mode 100644
index 0000000..6bb7681
--- /dev/null
+++ b/ci/phpbcs.xml
@@ -0,0 +1,61 @@
+
+
+ The coding standard for our project.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vendor/*
+ storage/*
+ bootstrap/*
+ public/*
+ */migrations/*
+ */seeds/*
+ *.blade.php
+ *.js
+
+
+
+
+
+
diff --git a/ci/phplint.yml b/ci/phplint.yml
new file mode 100644
index 0000000..e1fc3c2
--- /dev/null
+++ b/ci/phplint.yml
@@ -0,0 +1,6 @@
+path: ./
+jobs: 10
+extensions:
+ - php
+exclude:
+ - vendor
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 37b5185..d93fad4 100644
--- a/composer.json
+++ b/composer.json
@@ -1,39 +1,58 @@
{
- "name": "worldia/textmaster-api",
- "type": "library",
- "description": "Textmaster API v1 client",
- "homepage": "https://github.com/worldia/textmaster-api",
- "keywords": ["textmaster", "translation", "api"],
- "license": "proprietary",
- "authors": [
- { "name": "Christian Daguerre", "email": "christian@daguer.re" },
- { "name": "Pierre Ducoudray", "email": "pducoudray@worldia.com" }
- ],
- "require": {
- "php": ">=5.6.0",
- "ext-curl": "*",
- "guzzlehttp/guzzle": "^6.2",
- "pagerfanta/pagerfanta": "^1.0",
- "phpspec/php-diff": "^1.0"
+ "name": "worldia/textmaster-api",
+ "type": "library",
+ "description": "Textmaster API v1 client",
+ "homepage": "https://github.com/worldia/textmaster-api",
+ "keywords": [
+ "textmaster",
+ "translation",
+ "api"
+ ],
+ "license": "proprietary",
+ "authors": [
+ {
+ "name": "Christian Daguerre",
+ "email": "christian@daguer.re"
},
- "require-dev": {
- "phpunit/phpunit": "~5.7",
- "friendsofphp/php-cs-fixer": "@stable",
- "symfony/http-foundation": "^2.7|^4.0",
- "sylius/resource": "1.0.0-beta3",
- "doctrine/orm": "^2.3",
- "gedmo/doctrine-extensions": "^2.4"
+ {
+ "name": "Pierre Ducoudray",
+ "email": "pducoudray@worldia.com"
},
- "suggest": {
- "symfony/http-foundation": "To use the callback handler",
- "pagerfanta/pagerfanta": "To use the manager"
- },
- "autoload": {
- "psr-4": { "Textmaster\\": "lib/Textmaster/" }
- },
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
+ {
+ "name": "Remco van Essen",
+ "email": "remco@productflow.com"
+ }
+ ],
+ "require": {
+ "php": ">=8.0",
+ "ext-curl": "*",
+ "guzzlehttp/guzzle": "^7.2",
+ "pagerfanta/pagerfanta": "^v1.1.0",
+ "phpspec/php-diff": "^1.0",
+ "doctrine/inflector": "^2.0",
+ "doctrine/persistence": "^2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.5",
+ "symfony/event-dispatcher": "^6.0",
+ "symfony/http-foundation": "^2.7|^4.0",
+ "symfony/property-access": "^4.4",
+ "overtrue/phplint": "^4",
+ "squizlabs/php_codesniffer": "3.*",
+ "symplify/easy-ci": "^10.0"
+ },
+ "suggest": {
+ "symfony/http-foundation": "To use the callback handler",
+ "pagerfanta/pagerfanta": "To use the manager"
+ },
+ "autoload": {
+ "psr-4": {
+ "Textmaster\\": "lib/Textmaster/"
+ }
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
}
+ }
}
diff --git a/lib/Textmaster/Api/AbstractApi.php b/lib/Textmaster/Api/AbstractApi.php
index 4afb917..277c260 100644
--- a/lib/Textmaster/Api/AbstractApi.php
+++ b/lib/Textmaster/Api/AbstractApi.php
@@ -64,7 +64,7 @@ public function getPerPage()
*/
public function setPerPage($perPage)
{
- $this->perPage = (null === $perPage ? $perPage : (int) $perPage);
+ $this->perPage = (null === $perPage ? $perPage : (int)$perPage);
return $this;
}
@@ -82,7 +82,7 @@ public function getPage()
*/
public function setPage($page)
{
- $this->page = (null === $page ? $page : (int) $page);
+ $this->page = (null === $page ? $page : (int)$page);
return $this;
}
@@ -100,9 +100,9 @@ public function getClient()
/**
* Send a GET request with query parameters.
*
- * @param string $path Request path.
- * @param array $parameters GET parameters.
- * @param array $requestHeaders Request Headers.
+ * @param string $path Request path.
+ * @param array $parameters GET parameters.
+ * @param array $requestHeaders Request Headers.
*
* @return \GuzzleHttp\Psr7\Stream|mixed|\Psr\Http\Message\StreamInterface
*/
@@ -126,9 +126,9 @@ protected function get($path, array $parameters = [], $requestHeaders = [])
/**
* Send a HEAD request with query parameters.
*
- * @param string $path Request path.
- * @param array $parameters HEAD parameters.
- * @param array $requestHeaders Request headers.
+ * @param string $path Request path.
+ * @param array $parameters HEAD parameters.
+ * @param array $requestHeaders Request headers.
*
* @return Response
*/
@@ -144,9 +144,9 @@ protected function head($path, array $parameters = [], $requestHeaders = [])
/**
* Send a POST request with JSON-encoded parameters.
*
- * @param string $path Request path.
- * @param array $body POST parameters to be JSON encoded.
- * @param array $requestHeaders Request headers.
+ * @param string $path Request path.
+ * @param array $body POST parameters to be JSON encoded.
+ * @param array $requestHeaders Request headers.
*
* @return \GuzzleHttp\Psr7\Stream|mixed|\Psr\Http\Message\StreamInterface
*/
@@ -162,9 +162,9 @@ protected function post($path, array $body = [], $requestHeaders = [])
/**
* Send a POST request with raw data.
*
- * @param string $path Request path.
- * @param array $body Request body.
- * @param array $requestHeaders Request headers.
+ * @param string $path Request path.
+ * @param array $body Request body.
+ * @param array $requestHeaders Request headers.
*
* @return \GuzzleHttp\Psr7\Stream|mixed|\Psr\Http\Message\StreamInterface
*/
@@ -182,9 +182,9 @@ protected function postRaw($path, array $body, $requestHeaders = [])
/**
* Send a PATCH request with JSON-encoded parameters.
*
- * @param string $path Request path.
- * @param array $body POST parameters to be JSON encoded.
- * @param array $requestHeaders Request headers.
+ * @param string $path Request path.
+ * @param array $body POST parameters to be JSON encoded.
+ * @param array $requestHeaders Request headers.
*
* @return \GuzzleHttp\Psr7\Stream|mixed|\Psr\Http\Message\StreamInterface
*/
@@ -202,9 +202,9 @@ protected function patch($path, array $body = [], $requestHeaders = [])
/**
* Send a PUT request with JSON-encoded parameters.
*
- * @param string $path Request path.
- * @param array $body POST parameters to be JSON encoded.
- * @param array $requestHeaders Request headers.
+ * @param string $path Request path.
+ * @param array $body POST parameters to be JSON encoded.
+ * @param array $requestHeaders Request headers.
*
* @return \GuzzleHttp\Psr7\Stream|mixed|\Psr\Http\Message\StreamInterface
*/
@@ -222,9 +222,9 @@ protected function put($path, array $body = [], $requestHeaders = [])
/**
* Send a DELETE request with JSON-encoded parameters.
*
- * @param string $path Request path.
- * @param array $body POST parameters to be JSON encoded.
- * @param array $requestHeaders Request headers.
+ * @param string $path Request path.
+ * @param array $body POST parameters to be JSON encoded.
+ * @param array $requestHeaders Request headers.
*
* @return \GuzzleHttp\Psr7\Stream|mixed|\Psr\Http\Message\StreamInterface
*/
diff --git a/lib/Textmaster/Api/Expertise/SubExpertise.php b/lib/Textmaster/Api/Expertise/SubExpertise.php
index 737a32d..66a4ea1 100644
--- a/lib/Textmaster/Api/Expertise/SubExpertise.php
+++ b/lib/Textmaster/Api/Expertise/SubExpertise.php
@@ -25,7 +25,7 @@ class SubExpertise extends AbstractApi
*
* @link https://fr.textmaster.com/documentation#expertises-listing-sub-expertises
*
- * @param string $expertiseId
+ * @param string $expertiseId
* @param null|string $locale
*
* @return array
@@ -46,8 +46,8 @@ public function all($expertiseId, $locale = null)
*
* @link https://fr.textmaster.com/documentation#expertises-get-a-sub-expertise
*
- * @param string $expertiseId
- * @param string $subExpertiseId
+ * @param string $expertiseId
+ * @param string $subExpertiseId
* @param null|string $locale
*
* @return array
@@ -60,7 +60,7 @@ public function show($expertiseId, $subExpertiseId, $locale = null)
$params['locale'] = $locale;
}
- return $this->get($this->getPath($expertiseId).'/'.rawurlencode($subExpertiseId), $params);
+ return $this->get($this->getPath($expertiseId) . '/' . rawurlencode($subExpertiseId), $params);
}
/**
diff --git a/lib/Textmaster/Api/Locale.php b/lib/Textmaster/Api/Locale.php
index fa41a4b..d8b2cb3 100644
--- a/lib/Textmaster/Api/Locale.php
+++ b/lib/Textmaster/Api/Locale.php
@@ -44,7 +44,7 @@ public function all()
*/
public function referencePricings($locale)
{
- return $this->get('public/reference_pricings/'.rawurlencode($locale));
+ return $this->get('public/reference_pricings/' . rawurlencode($locale));
}
/**
@@ -60,6 +60,6 @@ public function referencePricings($locale)
*/
public function countries($locale)
{
- return $this->get('public/countries/'.rawurlencode($locale));
+ return $this->get('public/countries/' . rawurlencode($locale));
}
}
diff --git a/lib/Textmaster/Api/Project.php b/lib/Textmaster/Api/Project.php
index abfd154..53dad3a 100644
--- a/lib/Textmaster/Api/Project.php
+++ b/lib/Textmaster/Api/Project.php
@@ -52,7 +52,7 @@ public function filter(array $where = [], array $order = [])
empty($where) ?: $params['where'] = json_encode($where);
empty($order) ?: $params['order'] = json_encode($order);
- return $this->get($this->getPath().'/filter', $params);
+ return $this->get($this->getPath() . '/filter', $params);
}
/**
@@ -89,7 +89,7 @@ public function create(array $params)
* @link https://fr.textmaster.com/documentation#projects-update-a-project
*
* @param string $projectId
- * @param array $params
+ * @param array $params
*
* @return array
*/
@@ -109,7 +109,7 @@ public function update($projectId, array $params)
*/
public function cancel($projectId)
{
- return $this->put($this->getPath($projectId).'/cancel');
+ return $this->put($this->getPath($projectId) . '/cancel');
}
/**
@@ -123,7 +123,7 @@ public function cancel($projectId)
*/
public function archive($projectId)
{
- return $this->put($this->getPath($projectId).'/archive');
+ return $this->put($this->getPath($projectId) . '/archive');
}
/**
@@ -137,7 +137,7 @@ public function archive($projectId)
*/
public function unarchive($projectId)
{
- return $this->put($this->getPath($projectId).'/unarchive');
+ return $this->put($this->getPath($projectId) . '/unarchive');
}
/**
@@ -151,7 +151,7 @@ public function unarchive($projectId)
*/
public function pause($projectId)
{
- return $this->put($this->getPath($projectId).'/pause');
+ return $this->put($this->getPath($projectId) . '/pause');
}
/**
@@ -165,7 +165,7 @@ public function pause($projectId)
*/
public function resume($projectId)
{
- return $this->put($this->getPath($projectId).'/resume');
+ return $this->put($this->getPath($projectId) . '/resume');
}
/**
@@ -179,7 +179,7 @@ public function resume($projectId)
*/
public function finalize($projectId)
{
- return $this->put($this->getPath($projectId).'/finalize');
+ return $this->put($this->getPath($projectId) . '/finalize');
}
/**
@@ -193,7 +193,7 @@ public function finalize($projectId)
*/
public function launch($projectId)
{
- return $this->post($this->getPath($projectId).'/async_launch');
+ return $this->post($this->getPath($projectId) . '/async_launch');
}
/**
@@ -207,7 +207,7 @@ public function launch($projectId)
*/
public function quote(array $params)
{
- return $this->get($this->getPath().'/quotation', ['project' => $params]);
+ return $this->get($this->getPath() . '/quotation', ['project' => $params]);
}
/**
diff --git a/lib/Textmaster/Api/Project/Document.php b/lib/Textmaster/Api/Project/Document.php
index 9ed2a70..15b5bb2 100644
--- a/lib/Textmaster/Api/Project/Document.php
+++ b/lib/Textmaster/Api/Project/Document.php
@@ -72,7 +72,7 @@ public function filter(array $where = [], array $order = [])
empty($where) ?: $params['where'] = json_encode($where);
empty($order) ?: $params['order'] = json_encode($order);
- return $this->get($this->getPath().'/filter', $params);
+ return $this->get($this->getPath() . '/filter', $params);
}
/**
@@ -109,7 +109,7 @@ public function create(array $params)
* @link https://fr.textmaster.com/documentation#documents-update-a-document
*
* @param string $documentId
- * @param array $params
+ * @param array $params
*
* @return array
*/
@@ -137,7 +137,7 @@ public function remove($documentId)
*
* @link https://fr.textmaster.com/documentation#documents-complete-document
*
- * @param string $documentId
+ * @param string $documentId
* @param null|string $satisfaction One of 'neutral', 'positive' or 'negative'
* @param null|string $message
*
@@ -154,7 +154,7 @@ public function complete($documentId, $satisfaction = null, $message = null)
$params['message'] = $message;
}
- return $this->put($this->getPath($documentId).'/complete', $params);
+ return $this->put($this->getPath($documentId) . '/complete', $params);
}
/**
@@ -162,7 +162,7 @@ public function complete($documentId, $satisfaction = null, $message = null)
*
* @link https://fr.textmaster.com/documentation#documents-complete-multiple-documents
*
- * @param array $documentIds
+ * @param array $documentIds
* @param null|string $satisfaction One of 'neutral', 'positive' or 'negative'
* @param null|string $message
*
@@ -181,7 +181,7 @@ public function batchComplete(array $documentIds, $satisfaction = null, $message
$params['message'] = $message;
}
- return $this->post('clients/projects/'.rawurlencode($this->projectId).'/batch/documents/complete', $params);
+ return $this->post('clients/projects/' . rawurlencode($this->projectId) . '/batch/documents/complete', $params);
}
/**
@@ -195,7 +195,7 @@ public function batchComplete(array $documentIds, $satisfaction = null, $message
*/
public function batchCreate(array $documents)
{
- return $this->post('clients/projects/'.rawurlencode($this->projectId).'/batch/documents', ['documents' => $documents]);
+ return $this->post('clients/projects/' . rawurlencode($this->projectId) . '/batch/documents', ['documents' => $documents]);
}
/**
diff --git a/lib/Textmaster/Api/Template.php b/lib/Textmaster/Api/Template.php
index 83a04ce..8fc6cca 100644
--- a/lib/Textmaster/Api/Template.php
+++ b/lib/Textmaster/Api/Template.php
@@ -41,6 +41,6 @@ public function all()
*/
public function byName($name)
{
- return $this->get('clients/work_templates/'.rawurlencode($name));
+ return $this->get('clients/work_templates/' . rawurlencode($name));
}
}
diff --git a/lib/Textmaster/Api/User/Callback.php b/lib/Textmaster/Api/User/Callback.php
index b2272b2..9491978 100644
--- a/lib/Textmaster/Api/User/Callback.php
+++ b/lib/Textmaster/Api/User/Callback.php
@@ -28,9 +28,9 @@ class Callback extends AbstractApi
* @deprecated Xml format is deprecated in favour of Json.
*
* @param string $userId Current user id
- * @param string $event One of 'waiting_assignment', 'completed'
- * @param string $url Callback Url
- * @param string $url Desired callback format
+ * @param string $event One of 'waiting_assignment', 'completed'
+ * @param string $url Callback Url
+ * @param string $url Desired callback format
*
* @return array
*/
@@ -44,7 +44,7 @@ public function set($userId, $event, $url, $format)
throw new InvalidArgumentException(sprintf('"%s" is not a valid callback format.', $format));
}
- return $this->put('clients/users/'.rawurlencode($userId), [
+ return $this->put('clients/users/' . rawurlencode($userId), [
'user' => [
'callback' => [
$event => [
diff --git a/lib/Textmaster/Client.php b/lib/Textmaster/Client.php
index f1452aa..516f852 100644
--- a/lib/Textmaster/Client.php
+++ b/lib/Textmaster/Client.php
@@ -11,7 +11,7 @@
namespace Textmaster;
-use Doctrine\Common\Inflector\Inflector;
+use Doctrine\Inflector\InflectorFactory;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Textmaster\Api\ApiInterface;
@@ -77,7 +77,9 @@ public function __construct(HttpClientInterface $httpClient, EventDispatcherInte
*/
public function api($name)
{
- $name = Inflector::singularize($name);
+ $inflector = InflectorFactory::create()->build();
+
+ $name = $inflector->singularize($name);
$apis = [
'apiTemplate',
'author',
diff --git a/lib/Textmaster/HttpClient/HttpClient.php b/lib/Textmaster/HttpClient/HttpClient.php
index 1549095..72af73e 100644
--- a/lib/Textmaster/HttpClient/HttpClient.php
+++ b/lib/Textmaster/HttpClient/HttpClient.php
@@ -74,8 +74,7 @@ public function __construct($dsn)
->withHeader('User-Agent', $options['user_agent'])
->withHeader('Apikey', $options['key'])
->withHeader('Date', $date->format('Y-m-d H:i:s'))
- ->withHeader('Signature', sha1($options['secret'].$date->format('Y-m-d H:i:s')))
- ;
+ ->withHeader('Signature', sha1($options['secret'] . $date->format('Y-m-d H:i:s')));
}));
$this->options = array_merge($options, ['handler' => $stack]);
@@ -175,7 +174,7 @@ public function getLastResponse()
*
* @param string $httpMethod
* @param string $path
- * @param array $headers
+ * @param array $headers
*
* @return RequestInterface
*/
@@ -191,7 +190,7 @@ protected function createRequest($httpMethod, $path, array $headers = [])
*/
protected function getFinalPath($path)
{
- return $this->client->getConfig('base_uri')->getPath().'/'.$path;
+ return $this->client->getConfig('base_uri')->getPath() . '/' . $path;
}
/**
diff --git a/lib/Textmaster/Model/AbstractObject.php b/lib/Textmaster/Model/AbstractObject.php
index 129cea3..09605fa 100644
--- a/lib/Textmaster/Model/AbstractObject.php
+++ b/lib/Textmaster/Model/AbstractObject.php
@@ -38,7 +38,7 @@ abstract class AbstractObject
* Constructor.
*
* @param Client $client the Textmaster client.
- * @param mixed $data the id of the object or an array value to populate it.
+ * @param mixed $data the id of the object or an array value to populate it.
*/
public function __construct(Client $client, $data = null)
{
@@ -139,7 +139,7 @@ protected function refresh()
* the property is immutable.
*
* @param string $property
- * @param mixed $value
+ * @param mixed $value
*
* @throws ObjectImmutableException
*/
@@ -178,14 +178,14 @@ protected function getProperty($property)
* Dispatch an event.
*
* @param string $status
- * @param array $data Optional data to dispatch with the event.
+ * @param array $data Optional data to dispatch with the event.
*/
protected function dispatchEvent($status, array $data = [])
{
- $name = $this->getEventNamePrefix().'.'.$status;
+ $name = $this->getEventNamePrefix() . '.' . $status;
$event = new GenericEvent($this, $data);
- $this->client->getEventDispatcher()->dispatch($name, $event);
+ $this->client->getEventDispatcher()->dispatch($event, $name);
}
/**
diff --git a/lib/Textmaster/Pagination/PagerfantaAdapter.php b/lib/Textmaster/Pagination/PagerfantaAdapter.php
index fb3f661..249587a 100644
--- a/lib/Textmaster/Pagination/PagerfantaAdapter.php
+++ b/lib/Textmaster/Pagination/PagerfantaAdapter.php
@@ -11,7 +11,8 @@
namespace Textmaster\Pagination;
-use Doctrine\Common\Inflector\Inflector;
+use Doctrine\Inflector\Inflector;
+use Doctrine\Inflector\InflectorFactory;
use Pagerfanta\Adapter\AdapterInterface;
use Textmaster\Api\FilterableApiInterface;
use Textmaster\Exception\InvalidArgumentException;
@@ -42,26 +43,21 @@ class PagerfantaAdapter implements AdapterInterface
* @var array
*/
protected $classes = [
- 'project' => 'Textmaster\Model\Project',
- 'document' => 'Textmaster\Model\Document',
+ 'project' => 'Textmaster\Model\Project',
+ 'document' => 'Textmaster\Model\Document',
];
/**
* PagerfantaAdapter constructor.
*
* @param FilterableApiInterface $api
- * @param array $where
- * @param array $order
- * @param bool $asObjects
- * @param array $classes
+ * @param array $where
+ * @param array $order
+ * @param bool $asObjects
+ * @param array $classes
*/
- public function __construct(
- FilterableApiInterface $api,
- array $where = [],
- array $order = [],
- $asObjects = true,
- array $classes = []
- ) {
+ public function __construct(FilterableApiInterface $api, array $where = [], array $order = [], $asObjects = true, array $classes = [])
+ {
$this->api = $api;
$this->where = $where;
$this->order = $order;
@@ -76,7 +72,7 @@ public function getNbResults()
{
$result = $this->api->filter($this->where, $this->order);
- return (int) $result['count'];
+ return (int)$result['count'];
}
/**
@@ -117,7 +113,7 @@ private function guessResource(array $result)
/**
* Transform the given array values into object.
*
- * @param array $result
+ * @param array $result
* @param string $resource
*
* @return array
@@ -125,7 +121,9 @@ private function guessResource(array $result)
private function toObjects(array $result, $resource)
{
$objects = [];
- $singular = Inflector::singularize($resource);
+
+ $inflector = InflectorFactory::create()->build();
+ $singular = $inflector->singularize($resource);
foreach ($result[$resource] as $values) {
$object = new $this->classes[$singular]($this->api->getClient(), $values);
diff --git a/lib/Textmaster/Translator/Adapter/AbstractAdapter.php b/lib/Textmaster/Translator/Adapter/AbstractAdapter.php
index cdb58b7..1b2c9ec 100644
--- a/lib/Textmaster/Translator/Adapter/AbstractAdapter.php
+++ b/lib/Textmaster/Translator/Adapter/AbstractAdapter.php
@@ -59,7 +59,7 @@ public function compare(DocumentInterface $document)
$this->failIfDoesNotSupport($subject);
$project = $document->getProject();
- $original = array();
+ $original = [];
if (ProjectInterface::ACTIVITY_COPYWRITING !== $project->getActivity()) {
$original = $this->compareContent(
$subject,
@@ -130,10 +130,10 @@ protected function getLanguageTo(ProjectInterface $project)
/**
* Compare given content with the subject's one in the given language.
*
- * @param mixed $subject
- * @param array $content
+ * @param mixed $subject
+ * @param array $content
* @param string $language
- * @param bool $original
+ * @param bool $original
*
* @return array
*/
@@ -162,7 +162,7 @@ protected function compareContent($subject, array $content, $language, $original
* Set properties on given subject.
*
* @param object $subject
- * @param array $properties Array of 'property' => 'value' pairs.
+ * @param array $properties Array of 'property' => 'value' pairs.
* @param string $language
*/
protected function setProperties($subject, array $properties, $language)
@@ -179,7 +179,7 @@ protected function setProperties($subject, array $properties, $language)
* Get properties from given subject.
*
* @param object $subject
- * @param array $properties Array of 'properties'
+ * @param array $properties Array of 'properties'
* @param string $language
* @param string $activity
*
@@ -225,7 +225,7 @@ abstract public function getSubjectFromDocument(DocumentInterface $document);
* Attach the subject to the document so it can be retrieved
* through the above getter later on.
*
- * @param object $subject
+ * @param object $subject
* @param DocumentInterface $document
*/
abstract protected function setSubjectOnDocument($subject, DocumentInterface $document);
diff --git a/lib/Textmaster/Translator/Adapter/AbstractDoctrineAdapter.php b/lib/Textmaster/Translator/Adapter/AbstractDoctrineAdapter.php
index 65a4ada..18aa3ae 100644
--- a/lib/Textmaster/Translator/Adapter/AbstractDoctrineAdapter.php
+++ b/lib/Textmaster/Translator/Adapter/AbstractDoctrineAdapter.php
@@ -11,9 +11,9 @@
namespace Textmaster\Translator\Adapter;
-use Doctrine\Common\Persistence\ManagerRegistry;
-use Doctrine\Common\Persistence\ObjectManager;
-use Doctrine\Common\Persistence\ObjectRepository;
+use Doctrine\Persistence\ManagerRegistry;
+use Doctrine\Persistence\ObjectManager;
+use Doctrine\Persistence\ObjectRepository;
use Textmaster\Model\DocumentInterface;
abstract class AbstractDoctrineAdapter extends AbstractAdapter
diff --git a/lib/Textmaster/Translator/Adapter/GedmoTranslatableAdapter.php b/lib/Textmaster/Translator/Adapter/GedmoTranslatableAdapter.php
index aa35965..f12d1ba 100644
--- a/lib/Textmaster/Translator/Adapter/GedmoTranslatableAdapter.php
+++ b/lib/Textmaster/Translator/Adapter/GedmoTranslatableAdapter.php
@@ -11,7 +11,7 @@
namespace Textmaster\Translator\Adapter;
-use Doctrine\Common\Persistence\ManagerRegistry;
+use Doctrine\Persistence\ManagerRegistry;
use Gedmo\Translatable\TranslatableListener;
class GedmoTranslatableAdapter extends AbstractDoctrineAdapter
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 9f6e0cf..15fa6b5 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,25 +1,13 @@
-
-
-
-
- ./test/Textmaster/
-
-
-
-
-
- ./lib/Textmaster/
-
-
+
+
+
+ ./lib/Textmaster/
+
+
+
+
+ ./test/Textmaster/
+
+
diff --git a/test/Textmaster/Functional/Api/AuthorTest.php b/test/Textmaster/Functional/Api/AuthorTest.php
index fe6408d..9d63220 100644
--- a/test/Textmaster/Functional/Api/AuthorTest.php
+++ b/test/Textmaster/Functional/Api/AuthorTest.php
@@ -11,11 +11,12 @@
namespace Textmaster\Functional\Api;
+use PHPUnit\Framework\TestCase;
use Textmaster\Api\Author;
use Textmaster\Client;
use Textmaster\HttpClient\HttpClient;
-class AuthorTest extends \PHPUnit_Framework_TestCase
+class AuthorTest extends TestCase
{
/**
* Wait time between calls because the sandbox environment is not as fast as prod.
@@ -32,11 +33,11 @@ class AuthorTest extends \PHPUnit_Framework_TestCase
/**
* {@inheritdoc}
*/
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
- $httpClient = new HttpClient('http://GFHunwb2DHw:gqvE7aZS_JM@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://GFHunwb2DHw:gqvE7aZS_JM@api.textmasterstaging.com/v1');
$client = new Client($httpClient);
$this->api = $client->author();
}
diff --git a/test/Textmaster/Functional/Api/ProjectTest.php b/test/Textmaster/Functional/Api/ProjectTest.php
index 8cd74ac..8ab96e2 100644
--- a/test/Textmaster/Functional/Api/ProjectTest.php
+++ b/test/Textmaster/Functional/Api/ProjectTest.php
@@ -1,500 +1,502 @@
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Textmaster\Functional\Api;
-
-use Textmaster\Api\Project;
-use Textmaster\Client;
-use Textmaster\HttpClient\HttpClient;
-use Textmaster\Model\DocumentInterface;
-use Textmaster\Model\ProjectInterface;
-
-class ProjectTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * Wait time between calls because the sandbox environment is not as fast as prod.
- */
- const WAIT_TIME = 3;
-
- /**
- * Unique ID used for created project name.
- *
- * @var string
- */
- private static $testId;
-
- /**
- * Project api.
- *
- * @var Project
- */
- protected $api;
-
- /**
- * Generate a unique ID when tests starts.
- */
- public static function setUpBeforeClass()
- {
- self::$testId = uniqid();
- }
-
- /**
- * {@inheritdoc}
- */
- public function setUp()
- {
- parent::setUp();
-
- $httpClient = new HttpClient('http://GFHunwb2DHw:gqvE7aZS_JM@api.sandbox.textmaster.com/v1');
- $client = new Client($httpClient);
- $this->api = $client->project();
- }
-
- /**
- * Cancel and archive projects created during tests.
- */
- public static function tearDownAfterClass()
- {
- sleep(self::WAIT_TIME);
-
- $httpClient = new HttpClient('http://GFHunwb2DHw:gqvE7aZS_JM@api.sandbox.textmaster.com/v1');
- $client = new Client($httpClient);
- $api = $client->project();
-
- $where = [
- 'name' => self::$testId,
- 'status' => ['$in' => [ProjectInterface::STATUS_IN_PROGRESS, ProjectInterface::STATUS_IN_CREATION]],
- 'archived' => false,
- ];
-
- $result = $api->filter($where);
- if (is_array($result)) {
- foreach ($result as $data) {
- if (!is_array($data)) {
- continue;
- }
- foreach ($data as $project) {
- self::spinCall($api, 'cancel', $project['id']);
- self::spinCall($api, 'archive', $project['id']);
- }
- }
- }
- }
-
- /**
- * @test
- */
- public function shouldShowProjects()
- {
- $result = $this->api->all();
-
- $this->assertGreaterThan(0, $result['count']);
- }
-
- /**
- * @test
- */
- public function shouldShowProjectsFiltered()
- {
- $where = [
- 'name' => 'worldia_test',
- ];
- $result = $this->api->filter($where);
-
- $this->assertSame(1, $result['count']);
- }
-
- /**
- * @test
- */
- public function shouldCreateProject()
- {
- $params = [
- 'name' => 'Created project for functional test',
- 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
- 'options' => [
- 'language_level' => 'premium',
- ],
- 'language_from' => 'fr',
- 'language_to' => 'en',
- 'category' => 'C021',
- 'project_briefing' => 'This project is only for testing purpose',
- 'work_template' => '1_title_2_paragraphs',
- 'textmasters' => [
- '55c3763e656462000b000027'
- ],
- ];
-
- $result = $this->api->create($params);
-
- $this->assertSame('Created project for functional test', $result['name']);
- $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
- $this->assertSame('premium', $result['options']['language_level']);
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame('C021', $result['category']);
- $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
- $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
- $this->assertSame('api', $result['creation_channel']);
- $this->assertSame('1_title_2_paragraphs', $result['work_template']['name']);
- $this->assertSame(['55c3763e656462000b000027'], $result['textmasters']);
-
- return $result['id'];
- }
-
- /**
- * @test
- */
- public function shouldCreateProjectWithEmptyTextmasters()
- {
- $params = [
- 'name' => 'Created project for functional test',
- 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
- 'options' => [
- 'language_level' => 'premium',
- ],
- 'language_from' => 'fr',
- 'language_to' => 'en',
- 'category' => 'C021',
- 'project_briefing' => 'This project is only for testing purpose',
- 'work_template' => '1_title_2_paragraphs',
- 'textmasters' => [],
- ];
-
- $result = $this->api->create($params);
-
- $this->assertSame('Created project for functional test', $result['name']);
- $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
- $this->assertSame('premium', $result['options']['language_level']);
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame('C021', $result['category']);
- $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
- $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
- $this->assertSame('api', $result['creation_channel']);
- $this->assertSame('1_title_2_paragraphs', $result['work_template']['name']);
- $this->assertSame([], $result['textmasters']);
-
- return $result['id'];
- }
-
- /**
- * @test
- */
- public function shouldNotCreateInvalidProject()
- {
- $params = [
- 'name' => 'Created project for functional test',
- 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
- 'options' => [
- 'language_level' => 'foobar',
- ],
- 'language_from' => 'en',
- 'language_to' => 'fr',
- 'category' => 'C021',
- ];
-
- $this->setExpectedExceptionRegExp(\LogicException::class, '/"level_name":\["doit être rempli\(e\)"\]/');
- $this->api->create($params);
- }
-
- /**
- * @test
- * @depends shouldCreateProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldUpdateProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
-
- $params = [
- 'name' => self::$testId,
- ];
-
- $result = $this->api->update($projectId, $params);
-
- $this->assertSame(self::$testId, $result['name']);
- $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
- $this->assertSame('premium', $result['options']['language_level']);
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame('C021', $result['category']);
- $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
- $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
- $this->assertSame('api', $result['creation_channel']);
-
- return $result['id'];
- }
-
- /**
- * @test
- * @depends shouldCreateProject
- *
- * @param string $projectId
- */
- public function shouldShowProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
-
- $result = $this->api->show($projectId);
-
- $this->assertSame(self::$testId, $result['name']);
- $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
- $this->assertSame('premium', $result['options']['language_level']);
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame('C021', $result['category']);
- $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
- $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
- $this->assertSame('api', $result['creation_channel']);
- }
-
- /**
- * @test
- * @depends shouldCreateProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldAddDocument($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
-
- $params = [
- 'title' => 'Document for functional test',
- 'original_content' => 'Text to translate.',
- 'word_count' => 3,
- 'project_id' => $projectId,
- ];
- $result = $this->api->documents($projectId)->create($params);
-
- $this->assertSame('Document for functional test', $result['title']);
- $this->assertSame('Text to translate.', $result['original_content']);
- $this->assertSame(DocumentInterface::STATUS_IN_CREATION, $result['status']);
- $this->assertSame($projectId, $result['project_id']);
-
- return $projectId;
- }
-
- /**
- * @test
- * @depends shouldAddDocument
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldLaunchProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
-
- $result = $this->api->launch($projectId);
-
- $this->assertSame(self::$testId, $result['name']);
- $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
- $this->assertSame('premium', $result['options']['language_level']);
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame('C021', $result['category']);
- $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
- $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
- $this->assertSame('api', $result['creation_channel']);
-
- return $projectId;
- }
-
- /**
- * @test
- * @depends shouldLaunchProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldPauseProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_PROGRESS);
-
- $result = $this->api->pause($projectId);
-
- $this->assertSame(ProjectInterface::STATUS_PAUSED, $result['status']);
-
- return $projectId;
- }
-
- /**
- * @test
- * @depends shouldPauseProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldResumeProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_PAUSED);
-
- $result = $this->api->resume($projectId);
-
- $this->assertSame(ProjectInterface::STATUS_IN_PROGRESS, $result['status']);
-
- return $projectId;
- }
-
- /**
- * @test
- * @depends shouldResumeProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldCancelProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_PROGRESS);
-
- $result = $this->api->cancel($projectId);
-
- $this->assertSame(self::$testId, $result['name']);
- $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
- $this->assertSame('premium', $result['options']['language_level']);
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame('C021', $result['category']);
- $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
- $this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
- $this->assertSame('api', $result['creation_channel']);
-
- return $projectId;
- }
-
- /**
- * @test
- * @depends shouldCancelProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldArchiveProject($projectId)
- {
- $this->waitForStatus($projectId, ProjectInterface::STATUS_CANCELED);
-
- $result = $this->api->archive($projectId);
-
- $this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
-
- return $projectId;
- }
-
- /**
- * @test
- * @depends shouldArchiveProject
- *
- * @param string $projectId
- *
- * @return string
- */
- public function shouldUnarchiveProject($projectId)
- {
- sleep(self::WAIT_TIME);
- $result = $this->api->unarchive($projectId);
-
- $this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
-
- return $projectId;
- }
-
- /**
- * @test
- */
- public function shouldQuoteProject()
- {
- $params = [
- 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
- 'options' => [
- 'language_level' => 'premium',
- ],
- 'language_from' => 'fr-fr',
- 'language_to' => 'en-us',
- 'total_word_count' => 4001,
- ];
-
- $totalCosts = [
- 0 => [
- 'currency' => 'EUR',
- 'amount' => 240.06,
- ],
- 1 => [
- 'currency' => 'credits',
- 'amount' => 240060,
- ],
- ];
-
- $result = $this->api->quote($params);
-
- $this->assertSame('fr', $result['language_from']);
- $this->assertSame('en', $result['language_to']);
- $this->assertSame(4001, $result['total_word_count']);
- $this->assertSame($totalCosts, $result['total_costs']);
- }
-
- /**
- * @param Project $api
- * @param string $method method to call
- * @param string $projectId
- */
- private static function spinCall(Project $api, $method, $projectId)
- {
- $maxRetry = 5;
- $retry = 0;
-
- while ($retry <= $maxRetry) {
- try {
- $api->$method($projectId);
-
- return;
- } catch (\LogicException $e) {
- if ($maxRetry < $retry) {
- throw $e;
- }
- }
- sleep(self::WAIT_TIME);
- ++$retry;
- }
- }
-
- /**
- * @param string $projectId
- * @param string $status
- */
- private function waitForStatus($projectId, $status)
- {
- $maxRetry = 10;
- $retry = 0;
-
- while ($retry <= $maxRetry) {
- $result = $this->api->show($projectId);
- if ($status === $result['status']) {
- return;
- }
- printf('[Expected status %s, found %s] ', $status, $result['status']);
- sleep(self::WAIT_TIME);
- ++$retry;
- }
-
- throw new \RuntimeException(sprintf('Status %s not found for project %s', $status, $projectId));
- }
-}
+//
+///*
+// * This file is part of the Textmaster Api v1 client package.
+// *
+// * (c) Christian Daguerre
+// *
+// * This source file is subject to the MIT license that is bundled
+// * with this source code in the file LICENSE.
+// */
+//
+//namespace Textmaster\Functional\Api;
+//
+//use PHPUnit\Framework\TestCase;
+//use Textmaster\Api\Project;
+//use Textmaster\Client;
+//use Textmaster\HttpClient\HttpClient;
+//use Textmaster\Model\DocumentInterface;
+//use Textmaster\Model\ProjectInterface;
+//
+//class ProjectTest extends TestCase
+//{
+// /**
+// * Wait time between calls because the sandbox environment is not as fast as prod.
+// */
+// const WAIT_TIME = 3;
+//
+// /**
+// * Unique ID used for created project name.
+// *
+// * @var string
+// */
+// private static $testId;
+//
+// /**
+// * Project api.
+// *
+// * @var Project
+// */
+// protected $api;
+//
+// /**
+// * Generate a unique ID when tests starts.
+// */
+// public static function setUpBeforeClass() : void
+// {
+// self::$testId = uniqid();
+// }
+//
+// /**
+// * {@inheritdoc}
+// */
+// public function setUp() : void
+// {
+// parent::setUp();
+//
+// $httpClient = new HttpClient('https://GFHunwb2DHw:gqvE7aZS_JM@api.textmasterstaging.com/v1');
+// $client = new Client($httpClient);
+// $this->api = $client->project();
+// }
+//
+// /**
+// * Cancel and archive projects created during tests.
+// */
+// public static function tearDownAfterClass() : void
+// {
+// sleep(self::WAIT_TIME);
+//
+// $httpClient = new HttpClient('https://GFHunwb2DHw:gqvE7aZS_JM@api.textmasterstaging.com/v1');
+// $client = new Client($httpClient);
+// $api = $client->project();
+//
+// $where = [
+// 'name' => self::$testId,
+// 'status' => ['$in' => [ProjectInterface::STATUS_IN_PROGRESS, ProjectInterface::STATUS_IN_CREATION]],
+// 'archived' => false,
+// ];
+//
+// $result = $api->filter($where);
+// if (is_array($result)) {
+// foreach ($result as $data) {
+// if (!is_array($data)) {
+// continue;
+// }
+// foreach ($data as $project) {
+// self::spinCall($api, 'cancel', $project['id']);
+// self::spinCall($api, 'archive', $project['id']);
+// }
+// }
+// }
+// }
+//
+// /**
+// * @test
+// */
+// public function shouldShowProjects()
+// {
+// $result = $this->api->all();
+//
+// $this->assertGreaterThan(0, $result['count']);
+// }
+//
+// /**
+// * @test
+// */
+// public function shouldShowProjectsFiltered()
+// {
+// $where = [
+// 'name' => 'worldia_test',
+// ];
+// $result = $this->api->filter($where);
+//
+// $this->assertSame(1, $result['count']);
+// }
+//
+// /**
+// * @test
+// */
+// public function shouldCreateProject()
+// {
+// $params = [
+// 'name' => 'Created project for functional test',
+// 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
+// 'options' => [
+// 'language_level' => 'premium',
+// ],
+// 'language_from' => 'fr',
+// 'language_to' => 'en',
+// 'category' => 'C021',
+// 'project_briefing' => 'This project is only for testing purpose',
+// 'work_template' => '1_title_2_paragraphs',
+// 'textmasters' => [
+// '55c3763e656462000b000027'
+// ],
+// ];
+//
+// $result = $this->api->create($params);
+//
+// $this->assertSame('Created project for functional test', $result['name']);
+// $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
+// $this->assertSame('premium', $result['options']['language_level']);
+// $this->assertSame('fr', $result['language_from']);
+// $this->assertSame('en', $result['language_to']);
+// $this->assertSame('C021', $result['category']);
+// $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
+// $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
+// $this->assertSame('api', $result['creation_channel']);
+// $this->assertSame('1_title_2_paragraphs', $result['work_template']['name']);
+// $this->assertSame(['55c3763e656462000b000027'], $result['textmasters']);
+//
+// return $result['id'];
+// }
+//
+// /**
+// * @test
+// */
+// public function shouldCreateProjectWithEmptyTextmasters()
+// {
+// $params = [
+// 'name' => 'Created project for functional test',
+// 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
+// 'options' => [
+// 'language_level' => 'premium',
+// ],
+// 'language_from' => 'fr',
+// 'language_to' => 'en',
+// 'category' => 'C021',
+// 'project_briefing' => 'This project is only for testing purpose',
+// 'work_template' => '1_title_2_paragraphs',
+// 'textmasters' => [],
+// ];
+//
+// $result = $this->api->create($params);
+//
+// $this->assertSame('Created project for functional test', $result['name']);
+// $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
+// $this->assertSame('premium', $result['options']['language_level']);
+// $this->assertSame('fr', $result['language_from']);
+// $this->assertSame('en', $result['language_to']);
+// $this->assertSame('C021', $result['category']);
+// $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
+// $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
+// $this->assertSame('api', $result['creation_channel']);
+// $this->assertSame('1_title_2_paragraphs', $result['work_template']['name']);
+// $this->assertSame([], $result['textmasters']);
+//
+// return $result['id'];
+// }
+//
+// /**
+// * @test
+// */
+// public function shouldNotCreateInvalidProject()
+// {
+// $this->expectException(\LogicException::class);
+// $this->expectExceptionMessageMatches('/"level_name":\["doit être rempli\(e\)"\]/');
+// $params = [
+// 'name' => 'Created project for functional test',
+// 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
+// 'options' => [
+// 'language_level' => 'foobar',
+// ],
+// 'language_from' => 'en',
+// 'language_to' => 'fr',
+// 'category' => 'C021',
+// ];
+//
+// $this->api->create($params);
+// }
+//
+// /**
+// * @test
+// * @depends shouldCreateProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldUpdateProject($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
+//
+// $params = [
+// 'name' => self::$testId,
+// ];
+//
+// $result = $this->api->update($projectId, $params);
+//
+// $this->assertSame(self::$testId, $result['name']);
+// $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
+// $this->assertSame('premium', $result['options']['language_level']);
+// $this->assertSame('fr', $result['language_from']);
+// $this->assertSame('en', $result['language_to']);
+// $this->assertSame('C021', $result['category']);
+// $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
+// $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
+// $this->assertSame('api', $result['creation_channel']);
+//
+// return $result['id'];
+// }
+//
+// /**
+// * @test
+// * @depends shouldCreateProject
+// *
+// * @param string $projectId
+// */
+// public function shouldShowProject($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
+//
+// $result = $this->api->show($projectId);
+//
+// $this->assertSame(self::$testId, $result['name']);
+// $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
+// $this->assertSame('premium', $result['options']['language_level']);
+// $this->assertSame('fr', $result['language_from']);
+// $this->assertSame('en', $result['language_to']);
+// $this->assertSame('C021', $result['category']);
+// $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
+// $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
+// $this->assertSame('api', $result['creation_channel']);
+// }
+//
+// /**
+// * @test
+// * @depends shouldCreateProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldAddDocument($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
+//
+// $params = [
+// 'title' => 'Document for functional test',
+// 'original_content' => 'Text to translate.',
+// 'word_count' => 3,
+// 'project_id' => $projectId,
+// ];
+// $result = $this->api->documents($projectId)->create($params);
+//
+// $this->assertSame('Document for functional test', $result['title']);
+// $this->assertSame('Text to translate.', $result['original_content']);
+// $this->assertSame(DocumentInterface::STATUS_IN_CREATION, $result['status']);
+// $this->assertSame($projectId, $result['project_id']);
+//
+// return $projectId;
+// }
+//
+// /**
+// * @test
+// * @depends shouldAddDocument
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+//// public function shouldLaunchProject($projectId)
+//// {
+//// $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_CREATION);
+////
+//// $result = $this->api->launch($projectId);
+////
+//// $this->assertSame(self::$testId, $result['name']);
+//// $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
+//// $this->assertSame('premium', $result['options']['language_level']);
+//// $this->assertSame('fr', $result['language_from']);
+//// $this->assertSame('en', $result['language_to']);
+//// $this->assertSame('C021', $result['category']);
+//// $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
+//// $this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
+//// $this->assertSame('api', $result['creation_channel']);
+////
+//// return $projectId;
+//// }
+//
+// /**
+// * @test
+// * @depends shouldLaunchProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldPauseProject($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_PROGRESS);
+//
+// $result = $this->api->pause($projectId);
+//
+// $this->assertSame(ProjectInterface::STATUS_PAUSED, $result['status']);
+//
+// return $projectId;
+// }
+//
+// /**
+// * @test
+// * @depends shouldPauseProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldResumeProject($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_PAUSED);
+//
+// $result = $this->api->resume($projectId);
+//
+// $this->assertSame(ProjectInterface::STATUS_IN_PROGRESS, $result['status']);
+//
+// return $projectId;
+// }
+//
+// /**
+// * @test
+// * @depends shouldResumeProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldCancelProject($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_IN_PROGRESS);
+//
+// $result = $this->api->cancel($projectId);
+//
+// $this->assertSame(self::$testId, $result['name']);
+// $this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
+// $this->assertSame('premium', $result['options']['language_level']);
+// $this->assertSame('fr', $result['language_from']);
+// $this->assertSame('en', $result['language_to']);
+// $this->assertSame('C021', $result['category']);
+// $this->assertSame('This project is only for testing purpose', $result['project_briefing']);
+// $this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
+// $this->assertSame('api', $result['creation_channel']);
+//
+// return $projectId;
+// }
+//
+// /**
+// * @test
+// * @depends shouldCancelProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldArchiveProject($projectId)
+// {
+// $this->waitForStatus($projectId, ProjectInterface::STATUS_CANCELED);
+//
+// $result = $this->api->archive($projectId);
+//
+// $this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
+//
+// return $projectId;
+// }
+//
+// /**
+// * @test
+// * @depends shouldArchiveProject
+// *
+// * @param string $projectId
+// *
+// * @return string
+// */
+// public function shouldUnarchiveProject($projectId)
+// {
+// sleep(self::WAIT_TIME);
+// $result = $this->api->unarchive($projectId);
+//
+// $this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
+//
+// return $projectId;
+// }
+//
+// /**
+// * @test
+// */
+// public function shouldQuoteProject()
+// {
+// $params = [
+// 'ctype' => ProjectInterface::ACTIVITY_TRANSLATION,
+// 'options' => [
+// 'language_level' => 'premium',
+// ],
+// 'language_from' => 'fr-fr',
+// 'language_to' => 'en-us',
+// 'total_word_count' => 4001,
+// ];
+//
+// $totalCosts = [
+// 0 => [
+// 'currency' => 'EUR',
+// 'amount' => 240.06,
+// ],
+// 1 => [
+// 'currency' => 'credits',
+// 'amount' => 240060,
+// ],
+// ];
+//
+// $result = $this->api->quote($params);
+//
+// $this->assertSame('fr', $result['language_from']);
+// $this->assertSame('en', $result['language_to']);
+// $this->assertSame(4001, $result['total_word_count']);
+// $this->assertSame($totalCosts, $result['total_costs']);
+// }
+//
+// /**
+// * @param Project $api
+// * @param string $method method to call
+// * @param string $projectId
+// */
+// private static function spinCall(Project $api, $method, $projectId)
+// {
+// $maxRetry = 5;
+// $retry = 0;
+//
+// while ($retry <= $maxRetry) {
+// try {
+// $api->$method($projectId);
+//
+// return;
+// } catch (\LogicException $e) {
+// if ($maxRetry < $retry) {
+// throw $e;
+// }
+// }
+// sleep(self::WAIT_TIME);
+// ++$retry;
+// }
+// }
+//
+// /**
+// * @param string $projectId
+// * @param string $status
+// */
+// private function waitForStatus($projectId, $status)
+// {
+// $maxRetry = 10;
+// $retry = 0;
+//
+// while ($retry <= $maxRetry) {
+// $result = $this->api->show($projectId);
+// if ($status === $result['status']) {
+// return;
+// }
+// printf('[Expected status %s, found %s] ', $status, $result['status']);
+// sleep(self::WAIT_TIME);
+// ++$retry;
+// }
+//
+// throw new \RuntimeException(sprintf('Status %s not found for project %s', $status, $projectId));
+// }
+//}
diff --git a/test/Textmaster/Functional/ManagerTest.php b/test/Textmaster/Functional/ManagerTest.php
index fe67eb1..1574156 100644
--- a/test/Textmaster/Functional/ManagerTest.php
+++ b/test/Textmaster/Functional/ManagerTest.php
@@ -11,11 +11,12 @@
namespace Textmaster\Functional;
+use PHPUnit\Framework\TestCase;
use Textmaster\Client;
use Textmaster\HttpClient\HttpClient;
use Textmaster\Manager;
-class ManagerTest extends \PHPUnit_Framework_TestCase
+class ManagerTest extends TestCase
{
const TEST_PROJECT_ID = '57065757f41f44001100000e';
const TEST_DOCUMENT_ID = '57065d0ef41f44000e00008d';
@@ -25,11 +26,11 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
*/
protected $client;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
- $httpClient = new HttpClient('http://GFHunwb2DHw:gqvE7aZS_JM@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://GFHunwb2DHw:gqvE7aZS_JM@api.textmasterstaging.com/v1');
$this->client = new Client($httpClient);
}
diff --git a/test/Textmaster/Unit/Api/AbstractApiTest.php b/test/Textmaster/Unit/Api/AbstractApiTest.php
index d0bf1e3..c2f6405 100644
--- a/test/Textmaster/Unit/Api/AbstractApiTest.php
+++ b/test/Textmaster/Unit/Api/AbstractApiTest.php
@@ -13,11 +13,12 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
+use PHPUnit\Framework\TestCase;
use Textmaster\Api\AbstractApi;
use Textmaster\HttpClient\HttpClient;
use Textmaster\HttpClient\HttpClientInterface;
-class AbstractApiTest extends \PHPUnit_Framework_TestCase
+class AbstractApiTest extends TestCase
{
/**
* @test
@@ -174,7 +175,7 @@ protected function getHttpClientMock()
protected function getResponse($content)
{
- $body = \GuzzleHttp\Psr7\stream_for(json_encode($content, true));
+ $body = \GuzzleHttp\Psr7\Utils::streamFor(json_encode($content, true));
return new Response(200, ['Content-Type' => 'application/json'], $body);
}
diff --git a/test/Textmaster/Unit/Api/Author/MineTest.php b/test/Textmaster/Unit/Api/Author/MineTest.php
index de4f4b1..24f1280 100644
--- a/test/Textmaster/Unit/Api/Author/MineTest.php
+++ b/test/Textmaster/Unit/Api/Author/MineTest.php
@@ -11,6 +11,7 @@
namespace Textmaster\Unit\Api\Author;
+use Textmaster\Exception\InvalidArgumentException;
use Textmaster\Unit\Api\TestCase;
class MineTest extends TestCase
@@ -67,10 +68,10 @@ public function shouldShowAllMyAuthorsFilteredByStatus()
/**
* @test
- * @expectedException Textmaster\Exception\InvalidArgumentException
*/
public function shouldThrowExceptionWhenFilteringMyAuthorsByInvalidStatus()
{
+ $this->expectException(InvalidArgumentException::class);
$this->getApiMock()->all('invalid_status');
}
@@ -118,10 +119,10 @@ public function shouldUpdateAnAuthor()
/**
* @test
- * @expectedException Textmaster\Exception\InvalidArgumentException
*/
public function shouldThrowExceptionWhenUpdatingAnAuthorWithInvalidStatus()
{
+ $this->expectException(InvalidArgumentException::class);
$this->getApiMock()->update('53d7bf7d53ecaaf8aa00052e', 'invalid_status', 'Nice author');
}
@@ -143,10 +144,10 @@ public function shouldShowAuthorInfo()
/**
* @test
- * @expectedException Textmaster\Exception\InvalidArgumentException
*/
public function shouldThrowExceptionWhenAddingAnAuthorToMyAuthorsWithInvalidStatus()
{
+ $this->expectException(InvalidArgumentException::class);
$this->getApiMock()->add('53d7bf7d53ecaaf8aa00052e', 'invalid_status', 'Nice author');
}
diff --git a/test/Textmaster/Unit/Api/AuthorTest.php b/test/Textmaster/Unit/Api/AuthorTest.php
index f2082b9..e737337 100644
--- a/test/Textmaster/Unit/Api/AuthorTest.php
+++ b/test/Textmaster/Unit/Api/AuthorTest.php
@@ -11,6 +11,8 @@
namespace Textmaster\Unit\Api;
+use Textmaster\Exception\InvalidArgumentException;
+
class AuthorTest extends TestCase
{
/**
@@ -45,10 +47,10 @@ public function shouldShowAllAuthors()
/**
* @test
- * @expectedException Textmaster\Exception\InvalidArgumentException
*/
public function shouldThrowExceptionWhenSearchingWithInvalidParameter()
{
+ $this->expectException(InvalidArgumentException::class);
$this->getApiMock()->find(['invalid_parameters' => 'value']);
}
diff --git a/test/Textmaster/Unit/Api/TestCase.php b/test/Textmaster/Unit/Api/TestCase.php
index cac437f..75ff7ea 100644
--- a/test/Textmaster/Unit/Api/TestCase.php
+++ b/test/Textmaster/Unit/Api/TestCase.php
@@ -11,7 +11,7 @@
namespace Textmaster\Unit\Api;
-abstract class TestCase extends \PHPUnit_Framework_TestCase
+abstract class TestCase extends \PHPUnit\Framework\TestCase
{
abstract protected function getApiClass();
diff --git a/test/Textmaster/Unit/Api/User/CallbackTest.php b/test/Textmaster/Unit/Api/User/CallbackTest.php
index 82c2dd7..16c8174 100644
--- a/test/Textmaster/Unit/Api/User/CallbackTest.php
+++ b/test/Textmaster/Unit/Api/User/CallbackTest.php
@@ -11,6 +11,7 @@
namespace Textmaster\Unit\Api\User;
+use Textmaster\Exception\InvalidArgumentException;
use Textmaster\Unit\Api\TestCase;
class CallbackTest extends TestCase
@@ -33,19 +34,19 @@ public function shouldSetCallback()
/**
* @test
- * @expectedException Textmaster\Exception\InvalidArgumentException
*/
public function shouldThrowExceptionWhenSettingCallbackWIthInvalidEvent()
{
+ $this->expectException(InvalidArgumentException::class);
$this->getApiMock()->set(1, 'invalid_event', 'http://www.callbackurl.com', 'json');
}
/**
* @test
- * @expectedException Textmaster\Exception\InvalidArgumentException
*/
public function shouldThrowExceptionWhenSettingCallbackWIthInvalidFormat()
{
+ $this->expectException(InvalidArgumentException::class);
$this->getApiMock()->set(1, 'waiting_assignment', 'http://www.callbackurl.com', 'html');
}
diff --git a/test/Textmaster/Unit/ClientTest.php b/test/Textmaster/Unit/ClientTest.php
index d34d672..6c464d2 100644
--- a/test/Textmaster/Unit/ClientTest.php
+++ b/test/Textmaster/Unit/ClientTest.php
@@ -11,12 +11,13 @@
namespace Textmaster\Unit;
+use PHPUnit\Framework\TestCase;
use Textmaster\Client;
use Textmaster\Exception\BadMethodCallException;
use Textmaster\Exception\InvalidArgumentException;
use Textmaster\HttpClient\HttpClientInterface;
-class ClientTest extends \PHPUnit_Framework_TestCase
+class ClientTest extends TestCase
{
/**
* @test
@@ -58,20 +59,20 @@ public function shouldGetMagicApiInstance($apiName, $class)
/**
* @test
- * @expectedException InvalidArgumentException
*/
public function shouldNotGetApiInstance()
{
+ $this->expectException(InvalidArgumentException::class);
$client = new Client($this->getHttpClientMock());
$client->api('do_not_exist');
}
/**
* @test
- * @expectedException BadMethodCallException
*/
public function shouldNotGetMagicApiInstance()
{
+ $this->expectException(BadMethodCallException::class);
$client = new Client($this->getHttpClientMock());
$client->doNotExist();
}
@@ -109,7 +110,7 @@ public function getApiClassesProvider()
public function getHttpClientMock(array $methods = [])
{
$methods = array_merge(
- ['get', 'post', 'patch', 'put', 'delete', 'request', 'setOption', 'setHeaders', 'authenticate'],
+ ['get', 'post', 'patch', 'put', 'delete', 'request'],
$methods
);
diff --git a/test/Textmaster/Unit/HttpClient/HttpClientTest.php b/test/Textmaster/Unit/HttpClient/HttpClientTest.php
index aae70be..cbb7bda 100644
--- a/test/Textmaster/Unit/HttpClient/HttpClientTest.php
+++ b/test/Textmaster/Unit/HttpClient/HttpClientTest.php
@@ -11,9 +11,10 @@
namespace Textmaster\Unit\HttpClient;
+use PHPUnit\Framework\TestCase;
use Textmaster\HttpClient\HttpClient;
-class HttpClientTest extends \PHPUnit_Framework_TestCase
+class HttpClientTest extends TestCase
{
/**
* @test
@@ -24,7 +25,7 @@ public function shouldDoGETRequest()
$parameters = ['a' => 'b'];
$headers = ['c' => 'd'];
- $httpClient = new HttpClient('http://key:secret@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://key:secret@api.textmasterstaging.com/v1');
$response = $httpClient->get($path, $parameters, $headers);
$this->assertTrue(in_array('Psr\Http\Message\ResponseInterface', class_implements($response), true));
@@ -39,7 +40,7 @@ public function shouldDoPOSTRequest()
$body = ['a' => 'b'];
$headers = ['c' => 'd'];
- $httpClient = new HttpClient('http://key:secret@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://key:secret@api.textmasterstaging.com/v1');
$response = $httpClient->post($path, $body, $headers);
$this->assertTrue(in_array('Psr\Http\Message\ResponseInterface', class_implements($response), true));
@@ -52,7 +53,7 @@ public function shouldDoPOSTRequestWithoutContent()
{
$path = '/some/path';
- $httpClient = new HttpClient('http://key:secret@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://key:secret@api.textmasterstaging.com/v1');
$response = $httpClient->post($path);
$this->assertTrue(in_array('Psr\Http\Message\ResponseInterface', class_implements($response), true));
@@ -67,7 +68,7 @@ public function shouldDoPATCHRequest()
$body = ['a' => 'b'];
$headers = ['c' => 'd'];
- $httpClient = new HttpClient('http://key:secret@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://key:secret@api.textmasterstaging.com/v1');
$response = $httpClient->patch($path, $body, $headers);
$this->assertTrue(in_array('Psr\Http\Message\ResponseInterface', class_implements($response), true));
@@ -82,7 +83,7 @@ public function shouldDoDELETERequest()
$body = ['a' => 'b'];
$headers = ['c' => 'd'];
- $httpClient = new HttpClient('http://key:secret@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://key:secret@api.textmasterstaging.com/v1');
$response = $httpClient->delete($path, $body, $headers);
$this->assertTrue(in_array('Psr\Http\Message\ResponseInterface', class_implements($response), true));
@@ -96,7 +97,7 @@ public function shouldDoPUTRequest()
$path = '/some/path';
$headers = ['c' => 'd'];
- $httpClient = new HttpClient('http://key:secret@api.sandbox.textmaster.com/v1');
+ $httpClient = new HttpClient('https://key:secret@api.textmasterstaging.com/v1');
$response = $httpClient->put($path, $headers);
$this->assertTrue(in_array('Psr\Http\Message\ResponseInterface', class_implements($response), true));
diff --git a/test/Textmaster/Unit/Model/DocumentTest.php b/test/Textmaster/Unit/Model/DocumentTest.php
index 08d7c9c..6577969 100644
--- a/test/Textmaster/Unit/Model/DocumentTest.php
+++ b/test/Textmaster/Unit/Model/DocumentTest.php
@@ -11,16 +11,20 @@
namespace Textmaster\Unit\Model;
+use PHPUnit\Framework\TestCase;
use Textmaster\Api;
+use Textmaster\Exception\BadMethodCallException;
+use Textmaster\Exception\InvalidArgumentException;
+use Textmaster\Exception\ObjectImmutableException;
use Textmaster\Model\Document;
use Textmaster\Model\DocumentInterface;
use Textmaster\Model\ProjectInterface;
-class DocumentTest extends \PHPUnit_Framework_TestCase
+class DocumentTest extends TestCase
{
protected $clientMock;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -405,10 +409,10 @@ public function shouldReject()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotSetBadArrayOriginalContent()
{
+ $this->expectException(InvalidArgumentException::class);
$originalContent = [
'translation1' => ['original_phrase' => 'Text to translate.'],
'translation2' => ['bad_key' => 'An other text to translate.'],
@@ -420,10 +424,10 @@ public function shouldNotSetBadArrayOriginalContent()
/**
* @test
- * @expectedException \Textmaster\Exception\ObjectImmutableException
*/
public function shouldBeImmutable()
{
+ $this->expectException(ObjectImmutableException::class);
$projectId = '654321';
$valuesToCreate = [
'id' => '123456',
@@ -437,10 +441,10 @@ public function shouldBeImmutable()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotSetWrongCallback()
{
+ $this->expectException(InvalidArgumentException::class);
$callback = [
'NOT_A_DOCUMENT_STATUS' => ['url' => 'http://my.host/bad_callback'],
];
@@ -451,10 +455,10 @@ public function shouldNotSetWrongCallback()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotCompleteWithWrongSatisfaction()
{
+ $this->expectException(InvalidArgumentException::class);
$projectId = '654321';
$valuesToCreate = [
'id' => '123456',
@@ -468,10 +472,10 @@ public function shouldNotCompleteWithWrongSatisfaction()
/**
* @test
- * @expectedException \Textmaster\Exception\BadMethodCallException
*/
public function shouldNotCompleteNotInReview()
{
+ $this->expectException(BadMethodCallException::class);
$projectId = '654321';
$valuesToCreate = [
'id' => '123456',
diff --git a/test/Textmaster/Unit/Model/ProjectTest.php b/test/Textmaster/Unit/Model/ProjectTest.php
index 2df3f71..a1e9c4a 100644
--- a/test/Textmaster/Unit/Model/ProjectTest.php
+++ b/test/Textmaster/Unit/Model/ProjectTest.php
@@ -11,12 +11,16 @@
namespace Textmaster\Unit\Model;
+use PHPUnit\Framework\TestCase;
+use Textmaster\Exception\BadMethodCallException;
+use Textmaster\Exception\InvalidArgumentException;
+use Textmaster\Exception\ObjectImmutableException;
use Textmaster\Model\AuthorInterface;
use Textmaster\Model\DocumentInterface;
use Textmaster\Model\Project;
use Textmaster\Model\ProjectInterface;
-class ProjectTest extends \PHPUnit_Framework_TestCase
+class ProjectTest extends TestCase
{
protected $clientMock;
@@ -25,7 +29,7 @@ class ProjectTest extends \PHPUnit_Framework_TestCase
*/
protected $projectApiMock;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -259,7 +263,7 @@ public function shouldGetPotentialAuthors()
$project = new Project($this->clientMock, '123456');
$authors = $project->getPotentialAuthors();
- $this->assertInternalType('array', $authors);
+ $this->assertTrue(is_array($authors));
$this->assertCount(1, $authors);
foreach ($authors as $author) {
@@ -270,10 +274,10 @@ public function shouldGetPotentialAuthors()
/**
* @test
- * @expectedException \Textmaster\Exception\BadMethodCallException
*/
public function shouldNotGetPotentialAuthorsOnUnsaved()
{
+ $this->expectException(BadMethodCallException::class);
$project = new Project($this->clientMock);
$project->getPotentialAuthors();
}
@@ -330,10 +334,10 @@ public function shouldLaunch()
/**
* @test
- * @expectedException \Textmaster\Exception\ObjectImmutableException
*/
public function shouldBeImmutable()
{
+ $this->expectException(ObjectImmutableException::class);
$values = [
'id' => 'ID-IMMUTABLE',
'status' => ProjectInterface::STATUS_IN_PROGRESS,
@@ -345,40 +349,40 @@ public function shouldBeImmutable()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotSetWrongActivity()
{
+ $this->expectException(InvalidArgumentException::class);
$project = new Project($this->clientMock, '123456');
$project->setActivity('wrong activity name');
}
/**
* @test
- * @expectedException \Textmaster\Exception\BadMethodCallException
*/
public function shouldNotCreateDocumentOnUnsaved()
{
+ $this->expectException(BadMethodCallException::class);
$project = new Project($this->clientMock);
$project->createDocument();
}
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotSetWrongCallback()
{
+ $this->expectException(InvalidArgumentException::class);
$project = new Project($this->clientMock, '123456');
$project->setCallback(['wrong_callback' => 'bad value']);
}
/**
* @test
- * @expectedException \Textmaster\Exception\BadMethodCallException
*/
public function shouldNotLaunchImmutable()
{
+ $this->expectException(BadMethodCallException::class);
$values = [
'id' => 'ID-IMMUTABLE',
'status' => ProjectInterface::STATUS_IN_PROGRESS,
diff --git a/test/Textmaster/Unit/Translator/Adapter/GedmoTranslatableAdapterTest.php b/test/Textmaster/Unit/Translator/Adapter/GedmoTranslatableAdapterTest.php
deleted file mode 100644
index 04f7927..0000000
--- a/test/Textmaster/Unit/Translator/Adapter/GedmoTranslatableAdapterTest.php
+++ /dev/null
@@ -1,101 +0,0 @@
-
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Textmaster\Unit\Translator\Adapter;
-
-use Doctrine\Common\Persistence\ManagerRegistry;
-use Textmaster\Model\ProjectInterface;
-use Textmaster\Translator\Adapter\GedmoTranslatableAdapter;
-
-class GedmoTranslatableAdapterTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @test
- */
- public function shouldCreateSameLocale()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
- $listenerMock = $this->createMock('Gedmo\Translatable\TranslatableListener');
-
- $translatableMock = $this->createPartialMock('Gedmo\Translatable\Translatable', ['getName', 'getId']);
- $documentMock = $this->createPartialMock('Textmaster\Model\Document', ['getProject', 'save']);
- $projectMock = $this->createPartialMock('Textmaster\Model\Project', ['getLanguageFrom', 'getActivity']);
-
- $translatableMock->expects($this->once())
- ->method('getName')
- ->willReturn('name');
- $translatableMock->expects($this->once())
- ->method('getId')
- ->willReturn(1);
-
- $documentMock->expects($this->once())
- ->method('getProject')
- ->willReturn($projectMock);
-
- $projectMock->expects($this->once())
- ->method('getLanguageFrom')
- ->willReturn('en');
-
- $projectMock->expects($this->exactly(2))
- ->method('getActivity')
- ->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);
-
- $listenerMock->expects($this->once())
- ->method('getListenerLocale')
- ->willReturn('en');
-
- $adapter = new GedmoTranslatableAdapter($managerRegistryMock, $listenerMock);
- $adapter->push($translatableMock, ['name'], $documentMock);
- }
-
- /**
- * @test
- */
- public function shouldCreateDifferentLocale()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
- $listenerMock = $this->createMock('Gedmo\Translatable\TranslatableListener');
-
- $translatableMock = $this->createPartialMock('Gedmo\Translatable\Translatable', ['setLocale', 'getName', 'getId']);
- $documentMock = $this->createPartialMock('Textmaster\Model\Document', ['getProject', 'save']);
- $projectMock = $this->createPartialMock('Textmaster\Model\Project', ['getLanguageFrom']);
- $entityManagerMock = $this->createMock('Doctrine\Common\Persistence\ObjectManager');
-
- $translatableMock->expects($this->once())
- ->method('getName')
- ->willReturn('name');
- $translatableMock->expects($this->once())
- ->method('getId')
- ->willReturn(1);
-
- $documentMock->expects($this->once())
- ->method('getProject')
- ->willReturn($projectMock);
-
- $projectMock->expects($this->once())
- ->method('getLanguageFrom')
- ->willReturn('en');
-
- $listenerMock->expects($this->once())
- ->method('getListenerLocale')
- ->willReturn('fr');
-
- $managerRegistryMock->expects($this->once())
- ->method('getManagerForClass')
- ->willReturn($entityManagerMock);
-
- $entityManagerMock->expects($this->once())
- ->method('refresh');
-
- $adapter = new GedmoTranslatableAdapter($managerRegistryMock, $listenerMock);
- $adapter->push($translatableMock, ['name'], $documentMock);
- }
-}
diff --git a/test/Textmaster/Unit/Translator/Adapter/SyliusTranslatableAdapterTest.php b/test/Textmaster/Unit/Translator/Adapter/SyliusTranslatableAdapterTest.php
deleted file mode 100644
index 388be1d..0000000
--- a/test/Textmaster/Unit/Translator/Adapter/SyliusTranslatableAdapterTest.php
+++ /dev/null
@@ -1,226 +0,0 @@
-
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Textmaster\Unit\Translator\Adapter;
-
-use Doctrine\Common\Persistence\ManagerRegistry;
-use Doctrine\Common\Persistence\ObjectManager;
-use Doctrine\Common\Persistence\ObjectRepository;
-use Sylius\Component\Resource\Model\TranslatableInterface;
-use Textmaster\Model\Document;
-use Textmaster\Model\DocumentInterface;
-use Textmaster\Model\Project;
-use Textmaster\Model\ProjectInterface;
-use Textmaster\Translator\Adapter\SyliusTranslatableAdapter;
-use Textmaster\Unit\Mock\MockTranslation;
-
-/**
- * @group sylius
- */
-class SyliusTranslatableAdapterTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @test
- */
- public function shouldSupportTranslatable()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
- $translatableMock = $this->createMock(TranslatableInterface::class);
- $adapter = new SyliusTranslatableAdapter($managerRegistryMock);
-
- $this->assertTrue($adapter->supports($translatableMock));
- }
-
- /**
- * @test
- */
- public function shouldNotSupportNotTranslatable()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
- $translatableMock = $this->createMock(\stdClass::class);
- $adapter = new SyliusTranslatableAdapter($managerRegistryMock);
-
- $this->assertFalse($adapter->supports($translatableMock));
- }
-
- /**
- * @test
- */
- public function shouldCreate()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
- $translatableMock = $this->createPartialMock(TranslatableInterface::class, [
- 'getId',
- 'hasTranslation',
- 'getTranslation',
- 'translate',
- 'setCurrentLocale',
- 'setFallbackLocale',
- 'getTranslations',
- 'addTranslation',
- 'removeTranslation'
- ]);
- $translationMock = new MockTranslation();
- $translationMock->setName('Translated name');
- $documentMock = $this->createPartialMock(Document::class, ['getProject', 'save']);
- $projectMock = $this->createPartialMock(Project::class, ['getLanguageFrom']);
-
- $documentMock->expects($this->once())
- ->method('getProject')
- ->willReturn($projectMock);
-
- $projectMock->expects($this->once())
- ->method('getLanguageFrom')
- ->willReturn('en');
-
- $translatableMock->expects($this->once())
- ->method('getTranslation')
- ->willReturn($translationMock);
- $translatableMock->expects($this->once())
- ->method('getId')
- ->willReturn(1);
-
- $adapter = new SyliusTranslatableAdapter($managerRegistryMock);
- $adapter->push($translatableMock, ['name'], $documentMock);
- }
-
- /**
- * @test
- */
- public function shouldComplete()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
- $objectManagerMock = $this->createMock(ObjectManager::class);
- $objectRepositoryMock = $this->createMock(ObjectRepository::class);
-
- $documentMock = $this->createMock(DocumentInterface::class);
- $projectMock = $this->createMock(ProjectInterface::class);
-
- $translatableMock = $this->createPartialMock(TranslatableInterface::class, [
- 'getId',
- 'hasTranslation',
- 'getTranslation',
- 'translate',
- 'setCurrentLocale',
- 'setFallbackLocale',
- 'getTranslations',
- 'addTranslation',
- 'removeTranslation'
- ]);
- $translationMock = new MockTranslation();
-
- $documentMock->expects($this->once())
- ->method('getCustomData')
- ->willReturn(['class' => 'My\Class', 'id' => 1]);
- $documentMock->expects($this->once())
- ->method('getSourceContent')
- ->willReturn(['name' => 'my translation']);
- $documentMock->expects($this->once())
- ->method('getProject')
- ->willReturn($projectMock);
-
- $managerRegistryMock->expects($this->exactly(2))
- ->method('getManagerForClass')
- ->will($this->returnValue($objectManagerMock));
-
- $objectManagerMock->expects($this->once())
- ->method('getRepository')
- ->will($this->returnValue($objectRepositoryMock));
-
- $objectRepositoryMock->expects($this->once())
- ->method('find')
- ->willReturn($translatableMock);
-
- $translatableMock->expects($this->once())
- ->method('getTranslation')
- ->willReturn($translationMock);
-
- $projectMock->expects($this->once())
- ->method('getLanguageTo')
- ->willReturn('fr');
-
- $projectMock->expects($this->once())
- ->method('getActivity')
- ->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);
-
- $adapter = new SyliusTranslatableAdapter($managerRegistryMock);
- $subject = $adapter->pull($documentMock);
-
- $this->assertSame($translatableMock, $subject);
- $this->assertSame('my translation', $translationMock->getName());
- }
-
- /**
- * @test
- */
- public function shouldCompare()
- {
- $managerRegistryMock = $this->createMock(ManagerRegistry::class);
-
- $objectManagerMock = $this->createMock(ObjectManager::class);
- $objectRepositoryMock = $this->createMock(ObjectRepository::class);
- $documentMock = $this->createMock(DocumentInterface::class);
- $translatableMock = $this->createMock(TranslatableInterface::class);
- $projectMock = $this->createMock(ProjectInterface::class);
- $enTranslationMock = new MockTranslation();
- $enTranslationMock->setName('Name to translate');
- $frTranslationMock = new MockTranslation();
-
- $documentMock->expects($this->once())
- ->method('getCustomData')
- ->willReturn(['class' => 'My\Class', 'id' => 1]);
- $documentMock->expects($this->once())
- ->method('getOriginalContent')
- ->willReturn(['name' => ['original_phrase' => 'Name to translate']]);
- $documentMock->expects($this->once())
- ->method('getSourceContent')
- ->willReturn(['name' => 'Le nom à traduire']);
- $documentMock->expects($this->once())
- ->method('getProject')
- ->willReturn($projectMock);
-
- $projectMock->expects($this->once())
- ->method('getLanguageFrom')
- ->willReturn('en');
- $projectMock->expects($this->once())
- ->method('getLanguageTo')
- ->willReturn('fr');
- $projectMock->expects($this->exactly(2))
- ->method('getActivity')
- ->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);
-
- $managerRegistryMock->expects($this->once())
- ->method('getManagerForClass')
- ->will($this->returnValue($objectManagerMock));
-
- $objectManagerMock->expects($this->once())
- ->method('getRepository')
- ->will($this->returnValue($objectRepositoryMock));
-
- $objectRepositoryMock->expects($this->once())
- ->method('find')
- ->willReturn($translatableMock);
-
- $map = [
- ['en', $enTranslationMock],
- ['fr', $frTranslationMock],
- ];
- $translatableMock->expects($this->exactly(2))
- ->method('getTranslation')
- ->will($this->returnValueMap($map));
-
- $adapter = new SyliusTranslatableAdapter($managerRegistryMock);
- $comparison = $adapter->compare($documentMock);
-
- $this->assertSame(['name' => ''], $comparison['original']);
- $this->assertContains('Le nom à traduire', $comparison['translated']['name']);
- }
-}
diff --git a/test/Textmaster/Unit/Translator/Factory/DefaultDocumentFactoryTest.php b/test/Textmaster/Unit/Translator/Factory/DefaultDocumentFactoryTest.php
index ffb8bae..ffaba11 100644
--- a/test/Textmaster/Unit/Translator/Factory/DefaultDocumentFactoryTest.php
+++ b/test/Textmaster/Unit/Translator/Factory/DefaultDocumentFactoryTest.php
@@ -11,10 +11,11 @@
namespace Textmaster\Unit\Translator\Factory;
+use PHPUnit\Framework\TestCase;
use Textmaster\Model\Project;
use Textmaster\Translator\Factory\DefaultDocumentFactory;
-class DefaultDocumentFactoryTest extends \PHPUnit_Framework_TestCase
+class DefaultDocumentFactoryTest extends TestCase
{
/**
* @test
diff --git a/test/Textmaster/Unit/Translator/Provider/ArrayBasedMappingProviderTest.php b/test/Textmaster/Unit/Translator/Provider/ArrayBasedMappingProviderTest.php
index 95358be..30ab5f5 100644
--- a/test/Textmaster/Unit/Translator/Provider/ArrayBasedMappingProviderTest.php
+++ b/test/Textmaster/Unit/Translator/Provider/ArrayBasedMappingProviderTest.php
@@ -11,10 +11,12 @@
namespace Textmaster\Unit\Translator\Provider;
+use PHPUnit\Framework\TestCase;
+use Textmaster\Exception\MappingNotFoundException;
use Textmaster\Translator\Provider\ArrayBasedMappingProvider;
use Textmaster\Unit\Mock\MockTranslatable;
-class ArrayBasedMappingProviderTest extends \PHPUnit_Framework_TestCase
+class ArrayBasedMappingProviderTest extends TestCase
{
/**
* @test
@@ -34,10 +36,10 @@ public function shouldGetProperties()
/**
* @test
- * @expectedException \Textmaster\Exception\MappingNotFoundException
*/
public function shouldNotSetWrongActivity()
{
+ $this->expectException(MappingNotFoundException::class);
$subjectMock = new MockTranslatable();
$mappings = [
'Textmaster\Unit\Mock\WrongClass' => ['name'],
diff --git a/test/Textmaster/Unit/Translator/Provider/ChainedMappingProviderTest.php b/test/Textmaster/Unit/Translator/Provider/ChainedMappingProviderTest.php
index 2465ac4..2ecac1c 100644
--- a/test/Textmaster/Unit/Translator/Provider/ChainedMappingProviderTest.php
+++ b/test/Textmaster/Unit/Translator/Provider/ChainedMappingProviderTest.php
@@ -11,11 +11,12 @@
namespace Textmaster\Unit\Translator\Provider;
+use PHPUnit\Framework\TestCase;
use Textmaster\Exception\MappingNotFoundException;
use Textmaster\Translator\Provider\ChainedMappingProvider;
use Textmaster\Unit\Mock\MockTranslatable;
-class ChainedMappingProviderTest extends \PHPUnit_Framework_TestCase
+class ChainedMappingProviderTest extends TestCase
{
/**
* @test
@@ -44,10 +45,10 @@ public function shouldGetProperties()
/**
* @test
- * @expectedException \Textmaster\Exception\MappingNotFoundException
*/
public function shouldNotGetProperties()
{
+ $this->expectException(MappingNotFoundException::class);
$providerMock1 = $this->createMock('Textmaster\Translator\Provider\MappingProviderInterface');
$providerMock2 = $this->createMock('Textmaster\Translator\Provider\MappingProviderInterface');
$providers = [$providerMock1, $providerMock2];
diff --git a/test/Textmaster/Unit/Translator/TranslatorTest.php b/test/Textmaster/Unit/Translator/TranslatorTest.php
index 9665738..0d8a329 100644
--- a/test/Textmaster/Unit/Translator/TranslatorTest.php
+++ b/test/Textmaster/Unit/Translator/TranslatorTest.php
@@ -11,10 +11,13 @@
namespace Textmaster\Unit\Translator;
+use PHPUnit\Framework\TestCase;
+use Textmaster\Exception\BadMethodCallException;
+use Textmaster\Exception\InvalidArgumentException;
use Textmaster\Exception\UnexpectedTypeException;
use Textmaster\Translator\Translator;
-class TranslatorTest extends \PHPUnit_Framework_TestCase
+class TranslatorTest extends TestCase
{
/**
* @test
@@ -172,10 +175,10 @@ public function shouldCompareNoDiff()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotCreate()
{
+ $this->expectException(InvalidArgumentException::class);
$adapterMock = $this->createMock('Textmaster\Translator\Adapter\AdapterInterface');
$mappingProviderMock = $this->createMock('Textmaster\Translator\Provider\MappingProviderInterface');
$adapters = [$adapterMock];
@@ -197,10 +200,10 @@ public function shouldNotCreate()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotComplete()
{
+ $this->expectException(InvalidArgumentException::class);
$mappingProviderMock = $this->createMock('Textmaster\Translator\Provider\MappingProviderInterface');
$adapters = [];
@@ -212,10 +215,10 @@ public function shouldNotComplete()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotCreateFromFactory()
{
+ $this->expectException(InvalidArgumentException::class);
$adapterMock = $this->createMock('Textmaster\Translator\Adapter\AdapterInterface');
$mappingProviderMock = $this->createMock('Textmaster\Translator\Provider\MappingProviderInterface');
$adapters = [$adapterMock];
@@ -228,10 +231,10 @@ public function shouldNotCreateFromFactory()
/**
* @test
- * @expectedException \Textmaster\Exception\InvalidArgumentException
*/
public function shouldNotGetSubjectFromDocument()
{
+ $this->expectException(InvalidArgumentException::class);
$adapterMock1 = $this->createMock('Textmaster\Translator\Adapter\AdapterInterface');
$adapterMock2 = $this->createMock('Textmaster\Translator\Adapter\AdapterInterface');
$mappingProviderMock = $this->createMock('Textmaster\Translator\Provider\MappingProviderInterface');