diff --git a/.gitignore b/.gitignore index 42a6fdd..606de70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock vendor/ +.phpunit.result.cache diff --git a/README.md b/README.md index 7686993..354d158 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,37 @@ # DataCoder -[![Build Status](https://travis-ci.org/ExOrg/php-data-coder.svg?branch=master)](https://travis-ci.org/ExOrg/php-data-coder) +![example workflow](https://github.com/ExOrg/php-data-coder/actions/workflows/php.yml/badge.svg) -Extendable set of data and datafile encoders and decoders. It allows to transfer PHP arrays into data strings and datafiles and vice versa with chosen format like YAML and JSON. It provides encapsulation of various decoding and encoding mechanisms, unifies interface and exceptions handling. +Extendable set of data and data file encoders and decoders. It allows to transfer PHP arrays into data strings and datafiles and vice versa with chosen format like YAML and JSON. It provides encapsulation of various decoding and encoding mechanisms, unifies interface and exceptions handling. There are various groups of decoders and encoders -* With predefined data format - e.g. *JsonDataDecoder*, *YamlDatafileEncoder* -* With configurable data format - e.g. *DataDecoder*, *DatafileEncoder* -* For raw data - e.g. *JsonDataDecoder*, *DataEncoder* -* For data in the file - e.g. *YamlDatafileEncoder*, *DatafileDecoder* +* With predefined data format - e.g. *Coder\Json\Data\Decoder*, *Coder\Yaml\Datafile\Encoder* +* With configurable data format - e.g. *Coder\Data\Decoder*, *Coder\Datafile\Encoder* +* For raw data - e.g. *Coder\Json\Data\Decoder*, *Coder\Data\Encoder* +* For data in the file - e.g. *Coder\Yaml\Datafile\Encoder*, *Coder\Datafile\Decoder* ## Getting Started ### Prerequisities -* PHP 8.0+ -* [Composer](https://getcomposer.org/) 2.5.0+ +* [PHP](https://www.php.net/) 8.1 - 8.3 +* [Git](https://git-scm.com/) 2.25.1+ +* [Composer](https://getcomposer.org/) 2.6.0+ -### Installation +The instruction assumes using the Linux operating system or compatible tools for other operating systems. -The recommended way to install DataCoder into the source code of the project is to handle it as code dependency by [Composer](http://getcomposer.org). +### Installation -#### cURL, php8.0-cli and Git +#### php8.*-cli, Git and Composer required -The command line tool cURL will be used to to download *Composer* installer and *php8.0-cli* for and running it to install Composer. Git is needed by to downloading dependencies by the Composer. +The recommended way to install DataCoder into the source code of the project is to handle it as code dependency by [Composer](http://getcomposer.org). [Git](https://git-scm.com/) is needed to fetch packages from version control repositories. -#### Composer +The *php8.\*-cli* is needed for installing Composer. -The common way to intall Composer is downloading installer via *curl* tool and call the PHP interpreter to run it. +#### DataCoder installation -```bash -curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer -``` -Now composer is available as the command line tool and can be run by typing `composer` with appropriate parameters. - -#### DataCoder - -Add to your **composer.json** file following entry in the *require* section -``` -{ - "require": { - "exorg/data-coder": "^1.0.0" - } -} -``` -You can do it manually or by running the following command +Add to your **composer.json** file appropriate entry by running the following command ```bash composer require exorg/data-coder ``` @@ -53,7 +39,6 @@ If it's project set-up stage and no one dependency have been installed yet, run ```bash composer install ``` - If another dependencies have been intalled previously, run ```bash composer update @@ -65,14 +50,12 @@ The simplest way to autoload all needed files in executable file is attaching *a ```php require_once (__DIR__ . '/vendor/autoload.php'); - ``` ### Data Encoders with predefined format ```php - -use Exorg\DataCoder\JsonDataEncoder; +use ExOrg\DataCoder\Coder\Json\Data\Encoder; $data = [ "firstName" => "John", @@ -85,7 +68,7 @@ $data = [ ], ]; -$encoder = new JsonDataEncoder(); +$encoder = new Encoder(); $result = $encoder->encodeData($data); print($result); @@ -107,11 +90,9 @@ print($result); ### Data Decoders with predefined format ```php - -use Exorg\DataCoder\YamlDataDecoder; +use ExOrg\DataCoder\Coder\Yaml\Data\Decoder; $data = ' ---- firstName: John lastName: Smith address: @@ -119,10 +100,9 @@ address: city: New York state: NY postalCode: 10021-3100 -... '; -$decoder = new YamlDataDecoder(); +$decoder = new Decoder(); $result = $decoder->decodeData($data); print_r($result); @@ -147,7 +127,7 @@ Array ### Data Encoder with configurable format ```php -use Exorg\DataCoder\DataEncoder; +use ExOrg\DataCoder\Coder\Data\Encoder; $data = [ "firstName" => "John", @@ -160,7 +140,7 @@ $data = [ ], ]; -$encoder = new DataEncoder(); +$encoder = new Encoder(); $encoder->setDataFormat('yaml'); $result = $encoder->encodeData($data); @@ -168,22 +148,20 @@ print($result); ``` --- ``` ---- firstName: John lastName: Smith address: - streetAddress: 21 2nd Street - city: New York - state: NY - postalCode: 10021-3100 -... + streetAddress: '21 2nd Street' + city: 'New York' + state: NY + postalCode: 10021-3100 ``` ### Data Decoder with configurable format ```php -use Exorg\DataCoder\DataDecoder; +use ExOrg\DataCoder\Coder\Data\Decoder; $data = ' { @@ -199,7 +177,7 @@ $data = ' } '; -$decoder = new DataDecoder(); +$decoder = new Decoder(); $decoder->setDataFormat('json'); $result = $decoder->decodeData($data); @@ -225,16 +203,16 @@ Array ### Datafile Encoders and Decoders -Datafile Encoders and Decoders usage is similar to the Data Encoders and Decoders. There are coders with predefined data format like **JsonDatafileEncoder** or **YamlDatafileDecoder** and those, where data format can be chosen by function *setDataFormat*, just like in examples above - **DatafileEncoder** and **DatafileDecoder**. +Datafile Encoders and Decoders usage is similar to the Data Encoders and Decoders. There are coders with predefined data format like **Coder\Json\Datafile\Encoder** or **Coder\Yaml\Datafile\Decoder** and those, where data format can be chosen by function *setDataFormat*, just like in examples above - **Code\Datafile\Encoder** and **Code\Datafile\Decoder**. #### Data format recognizing by file extension -Datafile coders with configurable data format - **DatafileEncoder** and **DatafileDecoder** - can recognize data format by file extension. In that case, there is no need to set data format manually. +Datafile coders with configurable data format - **Coder\Datafile\Encoder** and **Coder\Datafile\Decoder** - can recognize data format by file extension. In that case, there is no need to set data format manually. -##### DatafileEncoder +##### Datafile Encoder ```php -use Exorg\DataCoder\DatafileEncoder; +use ExOrg\DataCoder\Coder\Datafile\Encoder; $data = [ "firstName" => "John", @@ -249,7 +227,7 @@ $data = [ $datafilePath = 'data.json'; -$encoder = new DatafileEncoder(); +$encoder = new Encoder(); $encoder->encodeFile($data, $datafilePath); print file_get_contents($datafilePath); @@ -268,31 +246,29 @@ print file_get_contents($datafilePath); } ``` -##### DatafileDecoder +##### Datafile Decoder ```php -use Exorg\DataCoder\DatafileDecoder; +use ExOrg\DataCoder\Coder\Datafile\Decoder; $datafilePath = 'data.yaml'; print file_get_contents($datafilePath); -$decoder = new DatafileDecoder(); +$decoder = new Decoder(); $data = $decoder->decodeFile($datafilePath); print_r($data); ``` --- ``` ---- firstName: John lastName: Smith address: - streetAddress: 21 2nd Street - city: New York - state: NY - postalCode: 10021-3100 -... + streetAddress: '21 2nd Street' + city: 'New York' + state: NY + postalCode: 10021-3100 Array ( [firstName] => John @@ -328,7 +304,7 @@ composer test ### Code style tests -This code follows [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-2](http://www.php-fig.org/psr/psr-2/) standards. +This code follows [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-12](http://www.php-fig.org/psr/psr-12/) standards. To run tests for code style write the following command in your command line inside the main DataCoder project directory @@ -355,13 +331,13 @@ composer check * [Remarkable](https://remarkableapp.github.io/) * [PHPUnit](https://phpunit.de/) * [PHPCodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) +* [Composer](https://getcomposer.org/) * [Git](https://git-scm.com/) * [GitHub](https://github.com/) -* [Travis](https://travis-ci.com/) ## Versioning -This project is versioning according to [SemVer](http://semver.org/) versioning standars. All available [releases](https://github.com/ExOrg/php-data-coder/releases) are [tagged](https://github.com/ExOrg/php-data-coder/tags). +This project is versioning according to [SemVer](http://semver.org/) versioning standars. All available [releases](https://github.com/ExOrg/php-data-coder/releases) are [tagged](https://github.com/ExOrg/php-data-coder/tags). ## Contributing diff --git a/composer.json b/composer.json index 53711af..1f48453 100644 --- a/composer.json +++ b/composer.json @@ -28,38 +28,16 @@ }, "autoload": { "psr-4": { - "Exorg\\DataCoder\\": [ - "src/", - "src/coders", - "src/coders/data_coders/", - "src/coders/data_coders/data_encoders/", - "src/coders/data_coders/data_decoders/", - "src/coders/datafile_coders/", - "src/coders/datafile_coders/datafile_encoders/", - "src/coders/datafile_coders/datafile_decoders/", - "src/data_format/", - "src/coder_builder/", - "src/file/" + "ExOrg\\DataCoder\\": [ + "src/" ] } }, "autoload-dev": { "psr-4": { - "Exorg\\DataCoder\\": [ - "tests/", - "tests/testing_environment/", - "tests/testing_environment/helpers/", - "tests/testing_environment/classes/", - "tests/unit_tests/coders/", - "tests/unit_tests/coders/data_coders/", - "tests/unit_tests/coders/data_coders/data_encoders/", - "tests/unit_tests/coders/data_coders/data_decoders/", - "tests/unit_tests/coders/datafile_coders/", - "tests/unit_tests/coders/datafile_coders/datafile_encoders/", - "tests/unit_tests/coders/datafile_coders/datafile_decoders/", - "tests/unit_tests/data_format/", - "tests/unit_tests/coder_builder/", - "tests/unit_tests/file/" + "ExOrg\\DataCoder\\": [ + "tests/unit_tests/", + "tests/fixtures/classes/" ] } }, diff --git a/phpcs.xml b/phpcs.xml index 925f393..2831708 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,5 +1,5 @@ - + The coding standard for PHPDataCoder. ./src diff --git a/src/coders/data_coders/data_decoders/AbstractDataDecoder.php b/src/Coder/Data/AbstractDecoder.php similarity index 90% rename from src/coders/data_coders/data_decoders/AbstractDataDecoder.php rename to src/Coder/Data/AbstractDecoder.php index 54197c0..5e15ee7 100644 --- a/src/coders/data_coders/data_decoders/AbstractDataDecoder.php +++ b/src/Coder/Data/AbstractDecoder.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; /** - * AbstractDataDecoder. + * Abstract Data Decoder. * Abstract class for Data Decoder * for concrete data format. * @@ -22,7 +22,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -abstract class AbstractDataDecoder +abstract class AbstractDecoder { /** * Validate data. diff --git a/src/coders/data_coders/data_encoders/AbstractDataEncoder.php b/src/Coder/Data/AbstractEncoder.php similarity index 92% rename from src/coders/data_coders/data_encoders/AbstractDataEncoder.php rename to src/Coder/Data/AbstractEncoder.php index 11875d8..c48b233 100644 --- a/src/coders/data_coders/data_encoders/AbstractDataEncoder.php +++ b/src/Coder/Data/AbstractEncoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; /** * AbstractDataEncoder. @@ -22,7 +22,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -abstract class AbstractDataEncoder +abstract class AbstractEncoder { /** * Validate data. diff --git a/src/coders/data_coders/data_decoders/DataDecoder.php b/src/Coder/Data/Decoder.php similarity index 78% rename from src/coders/data_coders/data_decoders/DataDecoder.php rename to src/Coder/Data/Decoder.php index a52c9dc..c116616 100644 --- a/src/coders/data_coders/data_decoders/DataDecoder.php +++ b/src/Coder/Data/Decoder.php @@ -9,7 +9,11 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; + +use ExOrg\DataCoder\Coder\Data\DecodingStrategyInterface; +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; +use ExOrg\DataCoder\DataFormat\DataFormatConfigurableTrait; /** * DataDecoder. @@ -22,7 +26,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DataDecoder +class Decoder implements DecodingStrategyInterface { use DataFormatConfigurableTrait; use CoderBuildingTrait; diff --git a/src/coders/data_coders/data_decoders/DataDecodingStrategyInterface.php b/src/Coder/Data/DecodingStrategyInterface.php similarity index 86% rename from src/coders/data_coders/data_decoders/DataDecodingStrategyInterface.php rename to src/Coder/Data/DecodingStrategyInterface.php index 94f47f4..ceb8e44 100644 --- a/src/coders/data_coders/data_decoders/DataDecodingStrategyInterface.php +++ b/src/Coder/Data/DecodingStrategyInterface.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; /** - * DataDecodingStrategyInterface. + * Data Decoding Strategy Interface. * Defines interface of particular data decoding strategy. * * @package DataCoder @@ -21,7 +21,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -interface DataDecodingStrategyInterface +interface DecodingStrategyInterface { /** * Decode data. diff --git a/src/coders/data_coders/data_encoders/DataEncoder.php b/src/Coder/Data/Encoder.php similarity index 78% rename from src/coders/data_coders/data_encoders/DataEncoder.php rename to src/Coder/Data/Encoder.php index 1bbf280..22da0e1 100644 --- a/src/coders/data_coders/data_encoders/DataEncoder.php +++ b/src/Coder/Data/Encoder.php @@ -9,7 +9,11 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; + +use ExOrg\DataCoder\Coder\Data\EncodingStrategyInterface; +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; +use ExOrg\DataCoder\DataFormat\DataFormatConfigurableTrait; /** * DataEncoder. @@ -22,7 +26,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DataEncoder +class Encoder implements EncodingStrategyInterface { use DataFormatConfigurableTrait; use CoderBuildingTrait; diff --git a/src/coders/data_coders/data_encoders/DataEncodingStrategyInterface.php b/src/Coder/Data/EncodingStrategyInterface.php similarity index 86% rename from src/coders/data_coders/data_encoders/DataEncodingStrategyInterface.php rename to src/Coder/Data/EncodingStrategyInterface.php index c6fc7e3..29c4377 100644 --- a/src/coders/data_coders/data_encoders/DataEncodingStrategyInterface.php +++ b/src/Coder/Data/EncodingStrategyInterface.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; /** - * DataEncodingStrategyInterface. + * Data Encoding Strategy Interface. * Defines interface of particular data encoding strategy. * * @package DataCoder @@ -21,7 +21,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -interface DataEncodingStrategyInterface +interface EncodingStrategyInterface { /** * Encode data. diff --git a/src/coders/datafile_coders/AbstractDatafileCoder.php b/src/Coder/Datafile/AbstractCoder.php similarity index 87% rename from src/coders/datafile_coders/AbstractDatafileCoder.php rename to src/Coder/Datafile/AbstractCoder.php index d04b640..2d1bac5 100644 --- a/src/coders/datafile_coders/AbstractDatafileCoder.php +++ b/src/Coder/Datafile/AbstractCoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Datafile; + +use ExOrg\DataCoder\DataFormat\DataFormatConfigurableTrait; +use ExOrg\DataCoder\File\File; /** - * AbstractDatafileCoder. + * Abstract Datafile Coder. * Abstract class for DatafileCoders * with configurable data format. * @@ -22,7 +25,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -abstract class AbstractDatafileCoder +abstract class AbstractCoder { use DataFormatConfigurableTrait; diff --git a/src/coders/datafile_coders/datafile_decoders/DatafileDecoder.php b/src/Coder/Datafile/Decoder.php similarity index 85% rename from src/coders/datafile_coders/datafile_decoders/DatafileDecoder.php rename to src/Coder/Datafile/Decoder.php index 0186572..92d35c4 100644 --- a/src/coders/datafile_coders/datafile_decoders/DatafileDecoder.php +++ b/src/Coder/Datafile/Decoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Datafile; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; +use ExOrg\DataCoder\File\File; /** - * DatafileDecoder. + * Datafile Decoder. * Allows to decode data file * accordingly the data format set directly * or defined by file extension. @@ -23,7 +26,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DatafileDecoder extends AbstractDatafileCoder +class Decoder extends AbstractCoder { use CoderBuildingTrait; diff --git a/src/coders/datafile_coders/datafile_encoders/DatafileEncoder.php b/src/Coder/Datafile/Encoder.php similarity index 85% rename from src/coders/datafile_coders/datafile_encoders/DatafileEncoder.php rename to src/Coder/Datafile/Encoder.php index f9a1380..ba68e4b 100644 --- a/src/coders/datafile_coders/datafile_encoders/DatafileEncoder.php +++ b/src/Coder/Datafile/Encoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Datafile; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; +use ExOrg\DataCoder\File\File; /** - * DatafileEncoder. + * Datafile Encoder. * Allows to encode data file * accordingly the data format set directly * or defined by file extension. @@ -23,7 +26,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DatafileEncoder extends AbstractDatafileCoder +class Encoder extends AbstractCoder { use CoderBuildingTrait; diff --git a/src/coders/data_coders/data_decoders/JsonDataDecoder.php b/src/Coder/Json/Data/Decoder.php similarity index 78% rename from src/coders/data_coders/data_decoders/JsonDataDecoder.php rename to src/Coder/Json/Data/Decoder.php index bf7a71e..2efd4f8 100644 --- a/src/coders/data_coders/data_decoders/JsonDataDecoder.php +++ b/src/Coder/Json/Data/Decoder.php @@ -9,10 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Data; + +use ExOrg\DataCoder\Coder\Data\AbstractDecoder; +use ExOrg\DataCoder\Coder\Data\DecodingStrategyInterface; +use ExOrg\DataCoder\DataFormat\DataFormatInvalidException; /** - * JsonDataDecoder. + * Json Data Decoder. * Data decoder for JSON format. * * @package DataCoder @@ -21,7 +25,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDataDecoder extends AbstractDataDecoder implements DataDecodingStrategyInterface +class Decoder extends AbstractDecoder implements DecodingStrategyInterface { /** * Decode given JSON data to PHP array. diff --git a/src/coders/data_coders/data_encoders/JsonDataEncoder.php b/src/Coder/Json/Data/Encoder.php similarity index 78% rename from src/coders/data_coders/data_encoders/JsonDataEncoder.php rename to src/Coder/Json/Data/Encoder.php index 7826aae..7973735 100644 --- a/src/coders/data_coders/data_encoders/JsonDataEncoder.php +++ b/src/Coder/Json/Data/Encoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Data; + +use ExOrg\DataCoder\Coder\Data\AbstractEncoder; +use ExOrg\DataCoder\Coder\Data\EncodingStrategyInterface; /** - * JsonDataEncoder. + * Json Data Encoder. * Data encoder for JSON format. * * @package DataCoder @@ -21,7 +24,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDataEncoder extends AbstractDataEncoder implements DataEncodingStrategyInterface +class Encoder extends AbstractEncoder implements EncodingStrategyInterface { /** * Encode given PHP array to JSON data. diff --git a/src/coders/datafile_coders/datafile_decoders/JsonDatafileDecoder.php b/src/Coder/Json/Datafile/Decoder.php similarity index 80% rename from src/coders/datafile_coders/datafile_decoders/JsonDatafileDecoder.php rename to src/Coder/Json/Datafile/Decoder.php index b1ee2e5..7b79d57 100644 --- a/src/coders/datafile_coders/datafile_decoders/JsonDatafileDecoder.php +++ b/src/Coder/Json/Datafile/Decoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Datafile; + +use ExOrg\DataCoder\File\File; +use ExOrg\DataCoder\Coder\Json\Data\Decoder as DataDecoder; /** - * JsonDatafileDecoder. + * Json Datafile Decoder. * Datafile decoder for JSON format. * * @package DataCoder @@ -21,7 +24,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDatafileDecoder +class Decoder { /** * Decode file content. @@ -36,7 +39,7 @@ public function decodeFile($filePath) $fileData = $file->getContent(); - $dataDecoder = new JsonDataDecoder(); + $dataDecoder = new DataDecoder(); $result = $dataDecoder->decodeData($fileData); return $result; diff --git a/src/coders/datafile_coders/datafile_encoders/JsonDatafileEncoder.php b/src/Coder/Json/Datafile/Encoder.php similarity index 80% rename from src/coders/datafile_coders/datafile_encoders/JsonDatafileEncoder.php rename to src/Coder/Json/Datafile/Encoder.php index 1fcad46..4d1b599 100644 --- a/src/coders/datafile_coders/datafile_encoders/JsonDatafileEncoder.php +++ b/src/Coder/Json/Datafile/Encoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Datafile; + +use ExOrg\DataCoder\File\File; +use ExOrg\DataCoder\Coder\Json\Data\Encoder as DataEncoder; /** - * JsonDatafileEncoder. + * Json Datafile Encoder. * Datafile encoder for JSON format. * * @package DataCoder @@ -21,7 +24,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDatafileEncoder +class Encoder { /** * Encode JSON data and write to the file. @@ -34,7 +37,7 @@ public function encodeFile($data, $filePath) { $file = new File($filePath); - $dataEncoder = new JsonDataEncoder(); + $dataEncoder = new DataEncoder(); $fileData = $dataEncoder->encodeData($data); $file->setContent($fileData); diff --git a/src/coders/data_coders/data_decoders/YamlDataDecoder.php b/src/Coder/Yaml/Data/Decoder.php similarity index 81% rename from src/coders/data_coders/data_decoders/YamlDataDecoder.php rename to src/Coder/Yaml/Data/Decoder.php index a0cb0df..6ef157a 100644 --- a/src/coders/data_coders/data_decoders/YamlDataDecoder.php +++ b/src/Coder/Yaml/Data/Decoder.php @@ -9,12 +9,15 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Data; +use ExOrg\DataCoder\Coder\Data\AbstractDecoder; +use ExOrg\DataCoder\Coder\Data\DecodingStrategyInterface; +use ExOrg\DataCoder\DataFormat\DataFormatInvalidException; use Symfony\Component\Yaml\Yaml; /** - * YamlDataDecoder. + * Yaml Data Decoder. * Data decoder for YAML format. * * @package DataCoder @@ -23,7 +26,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDataDecoder extends AbstractDataDecoder implements DataDecodingStrategyInterface +class Decoder extends AbstractDecoder implements DecodingStrategyInterface { /** * Decode given YAML data to PHP array. diff --git a/src/coders/data_coders/data_encoders/YamlDataEncoder.php b/src/Coder/Yaml/Data/Encoder.php similarity index 78% rename from src/coders/data_coders/data_encoders/YamlDataEncoder.php rename to src/Coder/Yaml/Data/Encoder.php index e31fed7..28b427a 100644 --- a/src/coders/data_coders/data_encoders/YamlDataEncoder.php +++ b/src/Coder/Yaml/Data/Encoder.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Data; +use ExOrg\DataCoder\Coder\Data\AbstractEncoder; +use ExOrg\DataCoder\Coder\Data\EncodingStrategyInterface; use Symfony\Component\Yaml\Yaml; /** - * YamlDataEncoder. + * Yaml Data Encoder. * Data encoder for YAML format. * * @package DataCoder @@ -23,7 +25,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDataEncoder extends AbstractDataEncoder implements DataEncodingStrategyInterface +class Encoder extends AbstractEncoder implements EncodingStrategyInterface { /** * Encode given PHP array to YAML data. diff --git a/src/coders/datafile_coders/datafile_decoders/YamlDatafileDecoder.php b/src/Coder/Yaml/Datafile/Decoder.php similarity index 80% rename from src/coders/datafile_coders/datafile_decoders/YamlDatafileDecoder.php rename to src/Coder/Yaml/Datafile/Decoder.php index fbb49d3..203c2fd 100644 --- a/src/coders/datafile_coders/datafile_decoders/YamlDatafileDecoder.php +++ b/src/Coder/Yaml/Datafile/Decoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Datafile; + +use ExOrg\DataCoder\File\File; +use ExOrg\DataCoder\Coder\Yaml\Data\Decoder as DataDecoder; /** - * YamlDatafileDecoder. + * Yaml Datafile Decoder. * Datafile decoder for YAML format. * * @package DataCoder @@ -21,7 +24,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDatafileDecoder +class Decoder { /** * Decode file content. @@ -36,7 +39,7 @@ public function decodeFile($filePath) $fileData = $file->getContent(); - $dataDecoder = new YamlDataDecoder(); + $dataDecoder = new DataDecoder(); $result = $dataDecoder->decodeData($fileData); return $result; diff --git a/src/coders/datafile_coders/datafile_encoders/YamlDatafileEncoder.php b/src/Coder/Yaml/Datafile/Encoder.php similarity index 80% rename from src/coders/datafile_coders/datafile_encoders/YamlDatafileEncoder.php rename to src/Coder/Yaml/Datafile/Encoder.php index 5786aa8..8806c27 100644 --- a/src/coders/datafile_coders/datafile_encoders/YamlDatafileEncoder.php +++ b/src/Coder/Yaml/Datafile/Encoder.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Datafile; + +use ExOrg\DataCoder\File\File; +use ExOrg\DataCoder\Coder\Yaml\Data\Encoder as DataEncoder; /** - * YamlDatafileEncoder. + * Yaml Datafile Encoder. * Datafile encoder for YAML format. * * @package DataCoder @@ -21,7 +24,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDatafileEncoder +class Encoder { /** * Encode YAML data and write to the file. @@ -34,7 +37,7 @@ public function encodeFile($data, $filePath) { $file = new File($filePath); - $dataEncoder = new YamlDataEncoder(); + $dataEncoder = new DataEncoder(); $fileData = $dataEncoder->encodeData($data); $file->setContent($fileData); diff --git a/src/coder_builder/CoderBuildingTrait.php b/src/CoderBuilder/CoderBuildingTrait.php similarity index 96% rename from src/coder_builder/CoderBuildingTrait.php rename to src/CoderBuilder/CoderBuildingTrait.php index 29895fe..bedcd9e 100644 --- a/src/coder_builder/CoderBuildingTrait.php +++ b/src/CoderBuilder/CoderBuildingTrait.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuilder; /** * CoderBuildingTrait. @@ -76,10 +76,12 @@ private function buildCoderClassName() $dataFormatPrefix = $this->establishDataFormatPrefix(); $coderTypePostfix = $this->extractCurrentClassNamePostfix(); - $coderClassName = __NAMESPACE__ + $coderClassName = 'ExOrg\\DataCoder\\Coder' . '\\' . $dataFormatPrefix + . '\\' . 'Data' + . '\\' . $coderTypePostfix; return $coderClassName; @@ -121,7 +123,7 @@ private function extractCurrentClassName() * into segmants * begun with upper case letter. * - * @return array: + * @return array */ private function splitCurrentClassName() { diff --git a/src/coder_builder/CoderClassNotFoundException.php b/src/CoderBuilder/CoderClassNotFoundException.php similarity index 94% rename from src/coder_builder/CoderClassNotFoundException.php rename to src/CoderBuilder/CoderClassNotFoundException.php index e2bfd47..6c909d6 100644 --- a/src/coder_builder/CoderClassNotFoundException.php +++ b/src/CoderBuilder/CoderClassNotFoundException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuilder; /** * CoderClassNotFoundException. diff --git a/src/data_format/DataFormat.php b/src/DataFormat/DataFormat.php similarity index 89% rename from src/data_format/DataFormat.php rename to src/DataFormat/DataFormat.php index cd4299f..e0d93c9 100644 --- a/src/data_format/DataFormat.php +++ b/src/DataFormat/DataFormat.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\DataFormat; use Garoevans\PhpEnum\Enum; @@ -25,7 +25,9 @@ */ class DataFormat extends Enum { + // phpcs:disable const __default = self::JSON; + // phpcs:disable const JSON = "JSON"; const YAML = "YAML"; diff --git a/src/data_format/DataFormatConfigurableTrait.php b/src/DataFormat/DataFormatConfigurableTrait.php similarity index 97% rename from src/data_format/DataFormatConfigurableTrait.php rename to src/DataFormat/DataFormatConfigurableTrait.php index b1a58b9..b89551c 100644 --- a/src/data_format/DataFormatConfigurableTrait.php +++ b/src/DataFormat/DataFormatConfigurableTrait.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\DataFormat; /** * DataFormatConfigurableTrait. diff --git a/src/data_format/DataFormatInvalidException.php b/src/DataFormat/DataFormatInvalidException.php similarity index 94% rename from src/data_format/DataFormatInvalidException.php rename to src/DataFormat/DataFormatInvalidException.php index 5b8248c..7edb489 100644 --- a/src/data_format/DataFormatInvalidException.php +++ b/src/DataFormat/DataFormatInvalidException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\DataFormat; /** * DataFormatInvalidException. diff --git a/src/file/File.php b/src/File/File.php similarity index 99% rename from src/file/File.php rename to src/File/File.php index 1113a34..e67d756 100644 --- a/src/file/File.php +++ b/src/File/File.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\File; /** * File. diff --git a/src/file/FileException.php b/src/File/FileException.php similarity index 92% rename from src/file/FileException.php rename to src/File/FileException.php index 82ea373..bb44e52 100644 --- a/src/file/FileException.php +++ b/src/File/FileException.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\File; /** - * NonexistentFileException. + * FileException. * Exception indicating that file * either doesn't exist * or cannot be read from the given place diff --git a/tests/testing_environment/classes/FormatDataDecoder.php b/tests/fixtures/classes/Coder/Format/Data/Decoder.php similarity index 91% rename from tests/testing_environment/classes/FormatDataDecoder.php rename to tests/fixtures/classes/Coder/Format/Data/Decoder.php index 87182b2..b0d5eeb 100644 --- a/tests/testing_environment/classes/FormatDataDecoder.php +++ b/tests/fixtures/classes/Coder/Format/Data/Decoder.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format\Data; /** - * FormatDataDecoder. + * Format Data Decoder. * Dummy data decoder for testing purposes only. * * @package DataCoder @@ -21,7 +21,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class FormatDataDecoder +class Decoder { /** * Simulate data decodind diff --git a/tests/testing_environment/classes/FormatDataEncoder.php b/tests/fixtures/classes/Coder/Format/Data/Encoder.php similarity index 80% rename from tests/testing_environment/classes/FormatDataEncoder.php rename to tests/fixtures/classes/Coder/Format/Data/Encoder.php index cd8d61a..69baae8 100644 --- a/tests/testing_environment/classes/FormatDataEncoder.php +++ b/tests/fixtures/classes/Coder/Format/Data/Encoder.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format\Data; /** - * FormatDataEncoder. + * Format Data Encoder. * Dummy data encoder for testing purposes only. * * @package DataCoder @@ -21,7 +21,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class FormatDataEncoder +class Encoder { /** * Simulate data encoding @@ -32,8 +32,11 @@ class FormatDataEncoder */ public function encodeData($data) { + $dataValues = array_values($data); + $dataCore = array_shift($dataValues); + return "" - . array_shift(array_values($data)) + . $dataCore . ""; } } diff --git a/tests/testing_environment/classes/Format1DataDecoder.php b/tests/fixtures/classes/Coder/Format1/Data/Decoder.php similarity index 92% rename from tests/testing_environment/classes/Format1DataDecoder.php rename to tests/fixtures/classes/Coder/Format1/Data/Decoder.php index 7085c73..a1092c5 100644 --- a/tests/testing_environment/classes/Format1DataDecoder.php +++ b/tests/fixtures/classes/Coder/Format1/Data/Decoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format1\Data; /** * Dummy data decoder for testing purposes only. @@ -20,7 +20,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class Format1DataDecoder +class Decoder { /** * Simulates data decodind diff --git a/tests/testing_environment/classes/Format1DataEncoder.php b/tests/fixtures/classes/Coder/Format1/Data/Encoder.php similarity index 92% rename from tests/testing_environment/classes/Format1DataEncoder.php rename to tests/fixtures/classes/Coder/Format1/Data/Encoder.php index 052d4db..a9bd0b6 100644 --- a/tests/testing_environment/classes/Format1DataEncoder.php +++ b/tests/fixtures/classes/Coder/Format1/Data/Encoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format1\Data; /** * Dummy data encoder for testing purposes only. @@ -20,7 +20,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class Format1DataEncoder +class Encoder { /** * Simulates data encoding diff --git a/tests/testing_environment/classes/Format2DataDecoder.php b/tests/fixtures/classes/Coder/Format2/Data/Decoder.php similarity index 92% rename from tests/testing_environment/classes/Format2DataDecoder.php rename to tests/fixtures/classes/Coder/Format2/Data/Decoder.php index 9cc0537..05c9833 100644 --- a/tests/testing_environment/classes/Format2DataDecoder.php +++ b/tests/fixtures/classes/Coder/Format2/Data/Decoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format2\Data; /** * Dummy data decoder for testing purposes only. @@ -20,7 +20,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class Format2DataDecoder +class Decoder { /** * Simulate data decodind diff --git a/tests/testing_environment/classes/Format2DataEncoder.php b/tests/fixtures/classes/Coder/Format2/Data/Encoder.php similarity index 92% rename from tests/testing_environment/classes/Format2DataEncoder.php rename to tests/fixtures/classes/Coder/Format2/Data/Encoder.php index 0d4a644..9fb4f5c 100644 --- a/tests/testing_environment/classes/Format2DataEncoder.php +++ b/tests/fixtures/classes/Coder/Format2/Data/Encoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format2\Data; /** * Dummy data encoder for testing purposes only. @@ -20,7 +20,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class Format2DataEncoder +class Encoder { /** * Simulates data encoding diff --git a/tests/testing_environment/classes/Format3DataDecoder.php b/tests/fixtures/classes/Coder/Format3/Data/Decoder.php similarity index 92% rename from tests/testing_environment/classes/Format3DataDecoder.php rename to tests/fixtures/classes/Coder/Format3/Data/Decoder.php index 79d6db3..9a60c64 100644 --- a/tests/testing_environment/classes/Format3DataDecoder.php +++ b/tests/fixtures/classes/Coder/Format3/Data/Decoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format3\Data; /** * Dummy data decoder for testing purposes only. @@ -20,7 +20,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class Format3DataDecoder +class Decoder { /** * Simulate data decodind diff --git a/tests/testing_environment/classes/Format3DataEncoder.php b/tests/fixtures/classes/Coder/Format3/Data/Encoder.php similarity index 92% rename from tests/testing_environment/classes/Format3DataEncoder.php rename to tests/fixtures/classes/Coder/Format3/Data/Encoder.php index 2aa1934..ee1bb9a 100644 --- a/tests/testing_environment/classes/Format3DataEncoder.php +++ b/tests/fixtures/classes/Coder/Format3/Data/Encoder.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Format3\Data; /** * Dummy data encoder for testing purposes only. @@ -20,7 +20,7 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class Format3DataEncoder +class Encoder { /** * Simulates data encoding diff --git a/tests/testing_environment/classes/DummyClassFormat1Decoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Decoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormat1Decoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Decoder.php index 699e45e..0e974db 100644 --- a/tests/testing_environment/classes/DummyClassFormat1Decoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Decoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormat1Encoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Encoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormat1Encoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Encoder.php index 13e7ebb..4cf5247 100644 --- a/tests/testing_environment/classes/DummyClassFormat1Encoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Encoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormat1Nocoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Nocoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormat1Nocoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Nocoder.php index 7d32ea1..5f84a10 100644 --- a/tests/testing_environment/classes/DummyClassFormat1Nocoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat1Nocoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormat2Decoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Decoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormat2Decoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Decoder.php index 7ee3c4c..7898746 100644 --- a/tests/testing_environment/classes/DummyClassFormat2Decoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Decoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormat2Encoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Encoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormat2Encoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Encoder.php index a70cc39..897a4f2 100644 --- a/tests/testing_environment/classes/DummyClassFormat2Encoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Encoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormat2Nocoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Nocoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormat2Nocoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Nocoder.php index 7f6830b..f082d60 100644 --- a/tests/testing_environment/classes/DummyClassFormat2Nocoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormat2Nocoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormatNotRecognizedDecoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNotRecognizedDecoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormatNotRecognizedDecoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNotRecognizedDecoder.php index ac05e24..82cc184 100644 --- a/tests/testing_environment/classes/DummyClassFormatNotRecognizedDecoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNotRecognizedDecoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormatNotRecognizedEncoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNotRecognizedEncoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormatNotRecognizedEncoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNotRecognizedEncoder.php index e08f64a..3256b0d 100644 --- a/tests/testing_environment/classes/DummyClassFormatNotRecognizedEncoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNotRecognizedEncoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormatNullDecoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNullDecoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormatNullDecoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNullDecoder.php index a235282..27421f8 100644 --- a/tests/testing_environment/classes/DummyClassFormatNullDecoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNullDecoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/DummyClassFormatNullEncoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNullEncoder.php similarity index 87% rename from tests/testing_environment/classes/DummyClassFormatNullEncoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNullEncoder.php index ec9612c..c996cbc 100644 --- a/tests/testing_environment/classes/DummyClassFormatNullEncoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/DummyClassFormatNullEncoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/Format1DummyClassDecoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassDecoder.php similarity index 86% rename from tests/testing_environment/classes/Format1DummyClassDecoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassDecoder.php index 6f4f749..7d6bd07 100644 --- a/tests/testing_environment/classes/Format1DummyClassDecoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassDecoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/Format1DummyClassEncoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassEncoder.php similarity index 86% rename from tests/testing_environment/classes/Format1DummyClassEncoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassEncoder.php index 7432725..ffe9de8 100644 --- a/tests/testing_environment/classes/Format1DummyClassEncoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassEncoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/Format1DummyClassNocoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassNocoder.php similarity index 86% rename from tests/testing_environment/classes/Format1DummyClassNocoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassNocoder.php index d74ea9b..8259104 100644 --- a/tests/testing_environment/classes/Format1DummyClassNocoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/Format1DummyClassNocoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/Format2DummyClassDecoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassDecoder.php similarity index 86% rename from tests/testing_environment/classes/Format2DummyClassDecoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassDecoder.php index 636b86d..64efd9c 100644 --- a/tests/testing_environment/classes/Format2DummyClassDecoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassDecoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/Format2DummyClassEncoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassEncoder.php similarity index 86% rename from tests/testing_environment/classes/Format2DummyClassEncoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassEncoder.php index 3e79eff..bc0d2cc 100644 --- a/tests/testing_environment/classes/Format2DummyClassEncoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassEncoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/Format2DummyClassNocoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassNocoder.php similarity index 86% rename from tests/testing_environment/classes/Format2DummyClassNocoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassNocoder.php index 2e79f94..daa9ae8 100644 --- a/tests/testing_environment/classes/Format2DummyClassNocoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/Format2DummyClassNocoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/FormatnotrecognizedDummyClassDecoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/FormatnotrecognizedDummyClassDecoder.php similarity index 87% rename from tests/testing_environment/classes/FormatnotrecognizedDummyClassDecoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/FormatnotrecognizedDummyClassDecoder.php index a29f197..e1d37a2 100644 --- a/tests/testing_environment/classes/FormatnotrecognizedDummyClassDecoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/FormatnotrecognizedDummyClassDecoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/classes/FormatnotrecognizedDummyClassEncoder.php b/tests/fixtures/classes/CoderBuildingTraitUsing/FormatnotrecognizedDummyClassEncoder.php similarity index 87% rename from tests/testing_environment/classes/FormatnotrecognizedDummyClassEncoder.php rename to tests/fixtures/classes/CoderBuildingTraitUsing/FormatnotrecognizedDummyClassEncoder.php index 9906abc..e056f0f 100644 --- a/tests/testing_environment/classes/FormatnotrecognizedDummyClassEncoder.php +++ b/tests/fixtures/classes/CoderBuildingTraitUsing/FormatnotrecognizedDummyClassEncoder.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuildingTraitUsing; + +use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait; /** * Dummy class for testing diff --git a/tests/testing_environment/data/decoded/.gitignore b/tests/fixtures/data/decoded/.gitignore similarity index 93% rename from tests/testing_environment/data/decoded/.gitignore rename to tests/fixtures/data/decoded/.gitignore index 594d698..e74254c 100644 --- a/tests/testing_environment/data/decoded/.gitignore +++ b/tests/fixtures/data/decoded/.gitignore @@ -1,2 +1 @@ self-test.php - diff --git a/tests/testing_environment/data/decoded/json.php b/tests/fixtures/data/decoded/json.php similarity index 100% rename from tests/testing_environment/data/decoded/json.php rename to tests/fixtures/data/decoded/json.php diff --git a/tests/testing_environment/data/decoded/yaml.php b/tests/fixtures/data/decoded/yaml.php similarity index 100% rename from tests/testing_environment/data/decoded/yaml.php rename to tests/fixtures/data/decoded/yaml.php diff --git a/tests/testing_environment/data/encoded/.gitignore b/tests/fixtures/data/encoded/.gitignore similarity index 93% rename from tests/testing_environment/data/encoded/.gitignore rename to tests/fixtures/data/encoded/.gitignore index 0eea5b8..66e4f09 100644 --- a/tests/testing_environment/data/encoded/.gitignore +++ b/tests/fixtures/data/encoded/.gitignore @@ -1,2 +1 @@ data.self-test - diff --git a/tests/testing_environment/data/encoded/data b/tests/fixtures/data/encoded/data similarity index 100% rename from tests/testing_environment/data/encoded/data rename to tests/fixtures/data/encoded/data diff --git a/tests/testing_environment/data/encoded/data.anotherformat b/tests/fixtures/data/encoded/data.anotherformat similarity index 100% rename from tests/testing_environment/data/encoded/data.anotherformat rename to tests/fixtures/data/encoded/data.anotherformat diff --git a/tests/testing_environment/data/encoded/data.format b/tests/fixtures/data/encoded/data.format similarity index 100% rename from tests/testing_environment/data/encoded/data.format rename to tests/fixtures/data/encoded/data.format diff --git a/tests/testing_environment/data/encoded/data.json b/tests/fixtures/data/encoded/data.json similarity index 100% rename from tests/testing_environment/data/encoded/data.json rename to tests/fixtures/data/encoded/data.json diff --git a/tests/testing_environment/data/encoded/data.nonexistentformat b/tests/fixtures/data/encoded/data.nonexistentformat similarity index 100% rename from tests/testing_environment/data/encoded/data.nonexistentformat rename to tests/fixtures/data/encoded/data.nonexistentformat diff --git a/tests/testing_environment/data/encoded/data.yaml b/tests/fixtures/data/encoded/data.yaml similarity index 100% rename from tests/testing_environment/data/encoded/data.yaml rename to tests/fixtures/data/encoded/data.yaml diff --git a/tests/testing_environment/files/directory/file-for-read b/tests/fixtures/files/directory/file-for-read similarity index 100% rename from tests/testing_environment/files/directory/file-for-read rename to tests/fixtures/files/directory/file-for-read diff --git a/tests/testing_environment/files/directory/file-for-write b/tests/fixtures/files/directory/file-for-write similarity index 100% rename from tests/testing_environment/files/directory/file-for-write rename to tests/fixtures/files/directory/file-for-write diff --git a/tests/testing_environment/files/file-for-read b/tests/fixtures/files/file-for-read similarity index 100% rename from tests/testing_environment/files/file-for-read rename to tests/fixtures/files/file-for-read diff --git a/tests/testing_environment/files/file-for-read.dat b/tests/fixtures/files/file-for-read.dat similarity index 100% rename from tests/testing_environment/files/file-for-read.dat rename to tests/fixtures/files/file-for-read.dat diff --git a/tests/testing_environment/files/file-for-read.ext b/tests/fixtures/files/file-for-read.ext similarity index 100% rename from tests/testing_environment/files/file-for-read.ext rename to tests/fixtures/files/file-for-read.ext diff --git a/tests/testing_environment/files/file-for-write b/tests/fixtures/files/file-for-write similarity index 100% rename from tests/testing_environment/files/file-for-write rename to tests/fixtures/files/file-for-write diff --git a/tests/testing_environment/files/file-for-write.dat b/tests/fixtures/files/file-for-write.dat similarity index 100% rename from tests/testing_environment/files/file-for-write.dat rename to tests/fixtures/files/file-for-write.dat diff --git a/tests/testing_environment/files/file-for-write.ext b/tests/fixtures/files/file-for-write.ext similarity index 100% rename from tests/testing_environment/files/file-for-write.ext rename to tests/fixtures/files/file-for-write.ext diff --git a/tests/testing_environment/files/self-test b/tests/fixtures/files/self-test similarity index 100% rename from tests/testing_environment/files/self-test rename to tests/fixtures/files/self-test diff --git a/tests/testing_environment/files/unreadable-directory/file-for-read b/tests/fixtures/files/unreadable-directory/file-for-read similarity index 100% rename from tests/testing_environment/files/unreadable-directory/file-for-read rename to tests/fixtures/files/unreadable-directory/file-for-read diff --git a/tests/testing_environment/files/unreadable-file b/tests/fixtures/files/unreadable-file similarity index 100% rename from tests/testing_environment/files/unreadable-file rename to tests/fixtures/files/unreadable-file diff --git a/tests/testing_environment/files/unwritable-directory/file-for-write b/tests/fixtures/files/unwritable-directory/file-for-write similarity index 100% rename from tests/testing_environment/files/unwritable-directory/file-for-write rename to tests/fixtures/files/unwritable-directory/file-for-write diff --git a/tests/testing_environment/files/unwritable-file b/tests/fixtures/files/unwritable-file similarity index 100% rename from tests/testing_environment/files/unwritable-file rename to tests/fixtures/files/unwritable-file diff --git a/tests/testing_environment/data/created/.gitignore b/tests/testing_environment/data/created/.gitignore deleted file mode 100644 index 22e8364..0000000 --- a/tests/testing_environment/data/created/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/* \ No newline at end of file diff --git a/tests/unit_tests/coders/data_coders/data_decoders/DataDecoderTest.php b/tests/unit_tests/Coder/Data/DecoderTest.php similarity index 89% rename from tests/unit_tests/coders/data_coders/data_decoders/DataDecoderTest.php rename to tests/unit_tests/Coder/Data/DecoderTest.php index 4d85bb3..e116159 100644 --- a/tests/unit_tests/coders/data_coders/data_decoders/DataDecoderTest.php +++ b/tests/unit_tests/Coder/Data/DecoderTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\Decapsulator\ObjectDecapsulator; /** * DataDecoderTest. @@ -24,8 +24,10 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DataDecoderTest extends TestCase +class DecoderTest extends TestCase { + const DECODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Data\Decoder'; + /** * Instance of tested class. * @@ -34,13 +36,13 @@ class DataDecoderTest extends TestCase private $dataDecoder; /** - * Test Exorg\DataCoder\DataDecoder class + * Test ExOrg\DataCoder\DataDecoder class * has been created. */ public function testDataDecoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DataDecoder') + class_exists(self::DECODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -52,7 +54,7 @@ public function testSetDataFormatFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'setDataFormat' ) ); @@ -120,7 +122,7 @@ public function testDecodeDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'decodeData' ) ); @@ -180,6 +182,6 @@ public static function dataProvider() */ protected function setUp(): void { - $this->dataDecoder = new DataDecoder(); + $this->dataDecoder = new Decoder(); } } diff --git a/tests/unit_tests/coders/data_coders/data_encoders/DataEncoderTest.php b/tests/unit_tests/Coder/Data/EncoderTest.php similarity index 87% rename from tests/unit_tests/coders/data_coders/data_encoders/DataEncoderTest.php rename to tests/unit_tests/Coder/Data/EncoderTest.php index 4aafac4..3c9b66d 100644 --- a/tests/unit_tests/coders/data_coders/data_encoders/DataEncoderTest.php +++ b/tests/unit_tests/Coder/Data/EncoderTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Data; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\Decapsulator\ObjectDecapsulator; use PHPUnit\Framework\TestCase; /** @@ -24,8 +24,10 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DataEncoderTest extends TestCase +class EncoderTest extends TestCase { + const ENCODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Data\Encoder'; + /** * Instance of tested class. * @@ -34,13 +36,13 @@ class DataEncoderTest extends TestCase private $dataEncoder; /** - * Test Exorg\DataCoder\DataEncoder class + * Test ExOrg\DataCoder\DataEncoder class * has been created. */ public function testDataEncoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DataEncoder') + class_exists(self::ENCODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -52,7 +54,7 @@ public function testSetDataFormatFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'setDataFormat' ) ); @@ -120,7 +122,7 @@ public function testEncodeDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'encodeData' ) ); @@ -137,8 +139,11 @@ public function testEncodeData($data) { $this->dataEncoder->setDataFormat('format'); + $dataValues = array_values($data); + $dataCore = array_shift($dataValues); + $expectedResult = "" - . array_shift(array_values($data)) + . $dataCore . ""; $actualResult = $this->dataEncoder->encodeData($data, 'file'); @@ -181,6 +186,6 @@ public static function dataProvider() */ protected function setUp(): void { - $this->dataEncoder = new DataEncoder(); + $this->dataEncoder = new Encoder(); } } diff --git a/tests/unit_tests/coders/datafile_coders/datafile_decoders/DatafileDecoderTest.php b/tests/unit_tests/Coder/Datafile/DecoderTest.php similarity index 86% rename from tests/unit_tests/coders/datafile_coders/datafile_decoders/DatafileDecoderTest.php rename to tests/unit_tests/Coder/Datafile/DecoderTest.php index e3cb246..b6ddf10 100644 --- a/tests/unit_tests/coders/datafile_coders/datafile_decoders/DatafileDecoderTest.php +++ b/tests/unit_tests/Coder/Datafile/DecoderTest.php @@ -9,10 +9,11 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Datafile; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; +use ExOrg\Decapsulator\ObjectDecapsulator; /** * DatafileDecoderTest. @@ -24,8 +25,12 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DatafileDecoderTest extends TestCase +class DecoderTest extends TestCase { + const DECODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Datafile\Decoder'; + const FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\File\FileException'; + const CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\CoderBuilder\CoderClassNotFoundException'; + /** * Helper for handling data file fixtures. * @@ -41,13 +46,13 @@ class DatafileDecoderTest extends TestCase private $datafileDecoder; /** - * Test Exorg\DataCoder\DatafileDecoder class + * Test ExOrg\DataCoder\DatafileDecoder class * has been created. */ public function testDatafileDecoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DatafileDecoder') + class_exists(self::DECODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -59,7 +64,7 @@ public function testSetDataFormatFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DatafileDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'setDataFormat' ) ); @@ -128,7 +133,7 @@ public function testDecodeFileFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DatafileDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'decodeFile' ) ); @@ -140,7 +145,7 @@ public function testDecodeFileFunctionExists() */ public function testDecodeFileWhenFileDoesNotExist() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('noexistent.format'); @@ -153,7 +158,7 @@ public function testDecodeFileWhenFileDoesNotExist() */ public function testDecodeFileWhenImproperDataFormatIsSet() { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('data.format'); @@ -185,7 +190,7 @@ public function testDecodeFileWhenDataFormatIsSet() */ public function testDecodeFileWhenDataFormatIsNotSetAndFileHasImproperExtension() { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('data.nonexistentformat'); @@ -252,6 +257,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->datafileDecoder = new DatafileDecoder(); + $this->datafileDecoder = new Decoder(); } } diff --git a/tests/unit_tests/coders/datafile_coders/datafile_encoders/DatafileEncoderTest.php b/tests/unit_tests/Coder/Datafile/EncoderTest.php similarity index 87% rename from tests/unit_tests/coders/datafile_coders/datafile_encoders/DatafileEncoderTest.php rename to tests/unit_tests/Coder/Datafile/EncoderTest.php index bce1952..39ad971 100644 --- a/tests/unit_tests/coders/datafile_coders/datafile_encoders/DatafileEncoderTest.php +++ b/tests/unit_tests/Coder/Datafile/EncoderTest.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Datafile; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; +use ExOrg\Decapsulator\ObjectDecapsulator; /** - * DatafileEncoderTest. + * Datafile Encoder Test. * PHPUnit test class for DatafileEncoder class. * * @package DataCoder @@ -24,8 +25,11 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class DatafileEncoderTest extends TestCase +class EncoderTest extends TestCase { + const ENCODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Datafile\Encoder'; + const CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\CoderBuilder\CoderClassNotFoundException'; + /** * Helper for handling data file fixtures. * @@ -41,13 +45,13 @@ class DatafileEncoderTest extends TestCase private $datafileEncoder; /** - * Test Exorg\DataCoder\DatafileEncoder class + * Test ExOrg\DataCoder\DatafileEncoder class * has been created. */ public function testDatafileEncoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DatafileEncoder') + class_exists(self::ENCODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -59,7 +63,7 @@ public function testSetDataFormatFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DatafileEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'setDataFormat' ) ); @@ -130,7 +134,7 @@ public function testEncodeFileFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DatafileEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'encodeFile' ) ); @@ -142,7 +146,7 @@ public function testEncodeFileFunctionExists() */ public function testEncodeFileWhenImproperDataFormatIsSet() { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildCreatedFilePath('data.format'); @@ -166,6 +170,7 @@ public function testEncodeFileWhenDataFormatIsSet() $actualResult = file_get_contents($dataFilePath); $this->assertEquals($expectedResult, $actualResult); + $this->assertTrue(true); } /** @@ -176,7 +181,7 @@ public function testEncodeFileWhenDataFormatIsSet() */ public function testEncodeFileWhenDataFormatIsNotSetAndFileHasImproperExtension() { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildCreatedFilePath('data.nonexistentformat'); @@ -245,6 +250,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->datafileEncoder = new DatafileEncoder(); + $this->datafileEncoder = new Encoder(); } } diff --git a/tests/unit_tests/coders/data_coders/data_decoders/JsonDataDecoderTest.php b/tests/unit_tests/Coder/Json/Data/DecoderTest.php similarity index 81% rename from tests/unit_tests/coders/data_coders/data_decoders/JsonDataDecoderTest.php rename to tests/unit_tests/Coder/Json/Data/DecoderTest.php index 45e7982..92cd9b5 100644 --- a/tests/unit_tests/coders/data_coders/data_decoders/JsonDataDecoderTest.php +++ b/tests/unit_tests/Coder/Json/Data/DecoderTest.php @@ -9,12 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Data; use PHPUnit\Framework\TestCase; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * JsonDataDecoderTest. + * Json Data Decoder Test. * PHPUnit test class for JsonDataDecoder class. * * @package DataCoder @@ -23,8 +24,11 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDataDecoderTest extends TestCase +class DecoderTest extends TestCase { + const DECODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Json\Data\Decoder'; + const DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\DataFormat\DataFormatInvalidException'; + /** * Decoded data format. */ @@ -51,7 +55,7 @@ class JsonDataDecoderTest extends TestCase public function testJsonDataDecoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\JsonDataDecoder') + class_exists(self::DECODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -63,7 +67,7 @@ public function testDecodeDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\JsonDataDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'decodeData' ) ); @@ -89,7 +93,7 @@ public function testDecodeDataWithNotStringData() */ public function testDecodeDataWithDataInIncorrectFormat() { - $this->expectException('\Exorg\DataCoder\DataFormatInvalidException'); + $this->expectException(self::DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $data = ''; @@ -125,6 +129,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->jsonDataDecoder = new JsonDataDecoder(); + $this->jsonDataDecoder = new Decoder(); } } diff --git a/tests/unit_tests/coders/data_coders/data_encoders/JsonDataEncoderTest.php b/tests/unit_tests/Coder/Json/Data/EncoderTest.php similarity index 84% rename from tests/unit_tests/coders/data_coders/data_encoders/JsonDataEncoderTest.php rename to tests/unit_tests/Coder/Json/Data/EncoderTest.php index 507b26e..e2465cb 100644 --- a/tests/unit_tests/coders/data_coders/data_encoders/JsonDataEncoderTest.php +++ b/tests/unit_tests/Coder/Json/Data/EncoderTest.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Data; use PHPUnit\Framework\TestCase; +// use ExOrg\DataCoder\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * JsonDataEncoderTest. + * Json Data Encoder Test. * PHPUnit test class for JsonDataEncoder class. * * @package DataCoder @@ -23,8 +25,10 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDataEncoderTest extends TestCase +class EncoderTest extends TestCase { + const ENCODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Json\Data\Encoder'; + /** * Encoded data format. */ @@ -51,7 +55,7 @@ class JsonDataEncoderTest extends TestCase public function testJsonDataEncoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\JsonDataEncoder') + class_exists(self::ENCODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -63,7 +67,7 @@ public function testEncodeDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\JsonDataEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'encodeData' ) ); @@ -111,6 +115,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->jsonDataEncoder = new JsonDataEncoder(); + $this->jsonDataEncoder = new Encoder(); } } diff --git a/tests/unit_tests/coders/datafile_coders/datafile_decoders/JsonDatafileDecoderTest.php b/tests/unit_tests/Coder/Json/Datafile/DecoderTest.php similarity index 76% rename from tests/unit_tests/coders/datafile_coders/datafile_decoders/JsonDatafileDecoderTest.php rename to tests/unit_tests/Coder/Json/Datafile/DecoderTest.php index a93d89f..ce071f7 100644 --- a/tests/unit_tests/coders/datafile_coders/datafile_decoders/JsonDatafileDecoderTest.php +++ b/tests/unit_tests/Coder/Json/Datafile/DecoderTest.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Datafile; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\Decapsulator\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * JsonDatafileDecoderTest. + * Json Datafile Decoder Test. * PHPUnit test class for JsonDatafileDecoder class. * * @package DataCoder @@ -24,8 +25,12 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDatafileDecoderTest extends TestCase +class DecoderTest extends TestCase { + const DECODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Json\Datafile\Decoder'; + const FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\File\FileException'; + const DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\DataFormat\DataFormatInvalidException'; + /** * Decoded data format. */ @@ -46,13 +51,13 @@ class JsonDatafileDecoderTest extends TestCase private $jsonDatafileDecoder; /** - * Test Exorg\DataCoder\JsonDatafileDecoder class + * Test ExOrg\DataCoder\JsonDatafileDecoder class * has been created. */ public function testJsonDatafileDecoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\JsonDatafileDecoder') + class_exists(self::DECODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -64,7 +69,7 @@ public function testDecodeFileFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\JsonDatafileDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'decodeFile' ) ); @@ -76,7 +81,7 @@ public function testDecodeFileFunctionExists() */ public function testDecodeFileWhenFileDoesNotExist() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('noexistent.format'); @@ -89,7 +94,7 @@ public function testDecodeFileWhenFileDoesNotExist() */ public function testDecodeFileWithIncorrectData() { - $this->expectException('\Exorg\DataCoder\DataFormatInvalidException'); + $this->expectException(self::DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('data.nonexistentformat'); @@ -125,6 +130,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->jsonDatafileDecoder = new JsonDatafileDecoder(); + $this->jsonDatafileDecoder = new Decoder(); } } diff --git a/tests/unit_tests/coders/datafile_coders/datafile_encoders/JsonDatafileEncoderTest.php b/tests/unit_tests/Coder/Json/Datafile/EncoderTest.php similarity index 84% rename from tests/unit_tests/coders/datafile_coders/datafile_encoders/JsonDatafileEncoderTest.php rename to tests/unit_tests/Coder/Json/Datafile/EncoderTest.php index bd67171..3b536da 100644 --- a/tests/unit_tests/coders/datafile_coders/datafile_encoders/JsonDatafileEncoderTest.php +++ b/tests/unit_tests/Coder/Json/Datafile/EncoderTest.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Json\Datafile; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\Decapsulator\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * JsonDatafileEncoderTest. + * Json Datafile Encoder Test. * PHPUnit test class for JsonDatafileEncoder class. * * @package DataCoder @@ -24,8 +25,10 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class JsonDatafileEncoderTest extends TestCase +class EncoderTest extends TestCase { + const ENCODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Json\Datafile\Encoder'; + /** * Encoded data format. */ @@ -46,13 +49,13 @@ class JsonDatafileEncoderTest extends TestCase private $jsonDatafileEncoder; /** - * Test Exorg\DataCoder\JsonDatafileEncoder class + * Test ExOrg\DataCoder\JsonDatafileEncoder class * has been created. */ public function testJsonDatafileEncoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\JsonDatafileEncoder') + class_exists(self::ENCODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -64,7 +67,7 @@ public function testEncodeFileFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\JsonDatafileEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'encodeFile' ) ); @@ -116,6 +119,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->jsonDatafileEncoder = new JsonDatafileEncoder(); + $this->jsonDatafileEncoder = new Encoder(); } } diff --git a/tests/unit_tests/coders/data_coders/data_decoders/YamlDataDecoderTest.php b/tests/unit_tests/Coder/Yaml/Data/DecoderTest.php similarity index 81% rename from tests/unit_tests/coders/data_coders/data_decoders/YamlDataDecoderTest.php rename to tests/unit_tests/Coder/Yaml/Data/DecoderTest.php index 9097358..6c89b8f 100644 --- a/tests/unit_tests/coders/data_coders/data_decoders/YamlDataDecoderTest.php +++ b/tests/unit_tests/Coder/Yaml/Data/DecoderTest.php @@ -9,12 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Data; use PHPUnit\Framework\TestCase; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * YamlDataDecoderTest. + * Yaml Data Decoder Test. * PHPUnit test class for YamlDataDecoder class. * * @package DataCoder @@ -23,8 +24,11 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDataDecoderTest extends TestCase +class DecoderTest extends TestCase { + const DECODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Yaml\Data\Decoder'; + const DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\DataFormat\DataFormatInvalidException'; + /** * Decoded data format. */ @@ -51,7 +55,7 @@ class YamlDataDecoderTest extends TestCase public function testYamlDataDecoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\YamlDataDecoder') + class_exists(self::DECODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -63,7 +67,7 @@ public function testDecodeDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\YamlDataDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'decodeData' ) ); @@ -89,7 +93,7 @@ public function testDecodeDataWithNotStringData() */ public function testDecodeDataWithDataInIncorrectFormat() { - $this->expectException('\Exorg\DataCoder\DataFormatInvalidException'); + $this->expectException(self::DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $data = ''; @@ -125,6 +129,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->yamlDataDecoder = new YamlDataDecoder(); + $this->yamlDataDecoder = new Decoder(); } } diff --git a/tests/unit_tests/coders/data_coders/data_encoders/YamlDataEncoderTest.php b/tests/unit_tests/Coder/Yaml/Data/EncoderTest.php similarity index 85% rename from tests/unit_tests/coders/data_coders/data_encoders/YamlDataEncoderTest.php rename to tests/unit_tests/Coder/Yaml/Data/EncoderTest.php index cc5a10d..5566a4c 100644 --- a/tests/unit_tests/coders/data_coders/data_encoders/YamlDataEncoderTest.php +++ b/tests/unit_tests/Coder/Yaml/Data/EncoderTest.php @@ -9,12 +9,13 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Data; use PHPUnit\Framework\TestCase; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * YamlDataEncoderTest. + * Yaml Data Encoder Test. * PHPUnit test class for YamlDataEncoder class. * * @package DataCoder @@ -23,8 +24,10 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDataEncoderTest extends TestCase +class EncoderTest extends TestCase { + const ENCODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Yaml\Data\Encoder'; + /** * Encoded data format. */ @@ -51,7 +54,7 @@ class YamlDataEncoderTest extends TestCase public function testYamlDataEncoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\YamlDataEncoder') + class_exists(self::ENCODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -63,7 +66,7 @@ public function testEncodeDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\YamlDataEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'encodeData' ) ); @@ -111,6 +114,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->yamlDataEncoder = new YamlDataEncoder(); + $this->yamlDataEncoder = new Encoder(); } } diff --git a/tests/unit_tests/coders/datafile_coders/datafile_decoders/YamlDatafileDecoderTest.php b/tests/unit_tests/Coder/Yaml/Datafile/DecoderTest.php similarity index 76% rename from tests/unit_tests/coders/datafile_coders/datafile_decoders/YamlDatafileDecoderTest.php rename to tests/unit_tests/Coder/Yaml/Datafile/DecoderTest.php index 8112d66..318bbda 100644 --- a/tests/unit_tests/coders/datafile_coders/datafile_decoders/YamlDatafileDecoderTest.php +++ b/tests/unit_tests/Coder/Yaml/Datafile/DecoderTest.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Datafile; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\Decapsulator\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * YamlDatafileDecoderTest. + * Yaml Datafile Decoder Test. * PHPUnit test class for YamlDatafileDecoder class. * * @package DataCoder @@ -24,8 +25,12 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDatafileDecoderTest extends TestCase +class DecoderTest extends TestCase { + const DECODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Yaml\Datafile\Decoder'; + const FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\File\FileException'; + const DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\DataFormat\DataFormatInvalidException'; + /** * Decoded data format. */ @@ -46,13 +51,13 @@ class YamlDatafileDecoderTest extends TestCase private $yamlDatafileDecoder; /** - * Test Exorg\DataCoder\YamlDatafileDecoder class + * Test ExOrg\DataCoder\YamlDatafileDecoder class * has been created. */ public function testYamlDatafileDecoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\YamlDatafileDecoder') + class_exists(self::DECODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -64,7 +69,7 @@ public function testDecodeFileFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\YamlDatafileDecoder', + self::DECODER_FULLY_QUALIFIED_CLASS_NAME, 'decodeFile' ) ); @@ -76,7 +81,7 @@ public function testDecodeFileFunctionExists() */ public function testDecodeFileWhenFileDoesNotExist() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('noexistent.format'); @@ -89,7 +94,7 @@ public function testDecodeFileWhenFileDoesNotExist() */ public function testDecodeFileWithIncorrectData() { - $this->expectException('\Exorg\DataCoder\DataFormatInvalidException'); + $this->expectException(self::DATA_FORMAT_INVALID_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $dataFilePath = self::$dataFileFixturesHelper->buildEncodedFilePath('data.nonexistentformat'); @@ -125,6 +130,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->yamlDatafileDecoder = new YamlDatafileDecoder(); + $this->yamlDatafileDecoder = new Decoder(); } } diff --git a/tests/unit_tests/coders/datafile_coders/datafile_encoders/YamlDatafileEncoderTest.php b/tests/unit_tests/Coder/Yaml/Datafile/EncoderTest.php similarity index 84% rename from tests/unit_tests/coders/datafile_coders/datafile_encoders/YamlDatafileEncoderTest.php rename to tests/unit_tests/Coder/Yaml/Datafile/EncoderTest.php index 1db4b72..02c5731 100644 --- a/tests/unit_tests/coders/datafile_coders/datafile_encoders/YamlDatafileEncoderTest.php +++ b/tests/unit_tests/Coder/Yaml/Datafile/EncoderTest.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Coder\Yaml\Datafile; use PHPUnit\Framework\TestCase; -use Exorg\Decapsulator\ObjectDecapsulator; +use ExOrg\Decapsulator\ObjectDecapsulator; +use ExOrg\DataCoder\Fixture\DataFileFixturesHelper; /** - * YamlDatafileEncoderTest. + * Yaml Datafile Encoder Test. * PHPUnit test class for YamlDatafileEncoder class. * * @package DataCoder @@ -24,8 +25,10 @@ * @license http://opensource.org/licenses/MIT MIT License * @link https://github.com/ExOrg/php-data-coder */ -class YamlDatafileEncoderTest extends TestCase +class EncoderTest extends TestCase { + const ENCODER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Coder\Yaml\Datafile\Encoder'; + /** * Encoded data format. */ @@ -46,13 +49,13 @@ class YamlDatafileEncoderTest extends TestCase private $yamlDatafileEncoder; /** - * Test Exorg\DataCoder\YamlDatafileEncoder class + * Test ExOrg\DataCoder\YamlDatafileEncoder class * has been created. */ public function testYamlDatafileEncoderClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\YamlDatafileEncoder') + class_exists(self::ENCODER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -64,7 +67,7 @@ public function testEncodeFileFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\YamlDatafileEncoder', + self::ENCODER_FULLY_QUALIFIED_CLASS_NAME, 'encodeFile' ) ); @@ -116,6 +119,6 @@ public static function setUpBeforeClass(): void */ protected function setUp(): void { - $this->yamlDatafileEncoder = new YamlDatafileEncoder(); + $this->yamlDatafileEncoder = new Encoder(); } } diff --git a/tests/unit_tests/coder_builder/CoderBuildingTraitTest.php b/tests/unit_tests/CoderBuilder/CoderBuildingTraitTest.php similarity index 54% rename from tests/unit_tests/coder_builder/CoderBuildingTraitTest.php rename to tests/unit_tests/CoderBuilder/CoderBuildingTraitTest.php index 9cb758a..9c2c42e 100644 --- a/tests/unit_tests/coder_builder/CoderBuildingTraitTest.php +++ b/tests/unit_tests/CoderBuilder/CoderBuildingTraitTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\CoderBuilder; use PHPUnit\Framework\TestCase; @@ -29,16 +29,20 @@ class CoderBuildingTraitTest extends TestCase * Namespace of the dummy coders classes * used to test trait. */ - const DUMMY_CODERS_NAMESPACE = __NAMESPACE__; + const CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE = 'ExOrg\DataCoder\CoderBuildingTraitUsing'; + const CODERS_NAMESPACE = 'ExOrg\DataCoder\Coder'; + + const CODE_BUILDING_TRAIT_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait'; + const CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\CoderBuilder\CoderClassNotFoundException'; /** - * Test Exorg\DatafilesParser\CoderBuildingTrait trait + * Test ExOrg\DatafilesParser\CoderBuildingTrait trait * has been implemented. */ public function testCoderBuildingTraitExists() { $this->assertTrue( - trait_exists('Exorg\DataCoder\CoderBuildingTrait') + trait_exists(self::CODE_BUILDING_TRAIT_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -50,7 +54,7 @@ public function testBuildCoderFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\CoderBuildingTrait', + self::CODE_BUILDING_TRAIT_FULLY_QUALIFIED_CLASS_NAME, 'buildCoder' ) ); @@ -67,7 +71,7 @@ public function testBuildCoderFunctionExists() */ public function testBuildCoderWhenTraitUsingClassHasImproperPostfix($traitUsingClassObject) { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $traitUsingClassObject->runBuildCoder(); } @@ -82,7 +86,7 @@ public function testBuildCoderWhenTraitUsingClassHasImproperPostfix($traitUsingC */ public function testBuildCoderWhenTraitUsingClassHasImproperPrefix($traitUsingClassObject) { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $traitUsingClassObject->runBuildCoder(); } @@ -96,7 +100,7 @@ public function testBuildCoderWhenTraitUsingClassHasImproperPrefix($traitUsingCl */ public function testBuildCoderWhenTraitUsingClassHasImproperDataFormat($traitUsingClassObject) { - $this->expectException('\Exorg\DataCoder\CoderClassNotFoundException'); + $this->expectException(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $traitUsingClassObject->runBuildCoder(); } @@ -128,10 +132,12 @@ public function testBuildCoder($traitUsingClassObject, $expectedCoderClass) public static function traitUsingClassObjectsWithImproperPostfixProvider() { return array( - array(new DummyClassFormat1Nocoder()), - array(new DummyClassFormat2Nocoder()), - array(new Format1DummyClassNocoder()), - array(new Format2DummyClassNocoder()), + // Classes with explicitly defined dataFormat + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormat1Nocoder')()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormat2Nocoder')()), + // Classes with no explicitly defined dataFormat (it's established from the class name first part) + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\Format1DummyClassNocoder')()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\Format2DummyClassNocoder')()), ); } @@ -144,8 +150,8 @@ public static function traitUsingClassObjectsWithImproperPostfixProvider() public static function traitUsingClassObjectsWithImproperPrefixProvider() { return array( - array(new FormatnotrecognizedDummyClassEncoder()), - array(new FormatnotrecognizedDummyClassDecoder()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\FormatnotrecognizedDummyClassEncoder')()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\FormatnotrecognizedDummyClassDecoder')()), ); } @@ -158,10 +164,10 @@ public static function traitUsingClassObjectsWithImproperPrefixProvider() public static function traitUsingClassObjectsWithImproperDataFormatProvider() { return array( - array(new DummyClassFormatNullEncoder()), - array(new DummyClassFormatNullDecoder()), - array(new DummyClassFormatNotRecognizedEncoder()), - array(new DummyClassFormatNotRecognizedDecoder()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormatNullEncoder')()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormatNullDecoder')()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormatNotRecognizedEncoder')()), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormatNotRecognizedDecoder')()), ); } @@ -176,14 +182,16 @@ public static function traitUsingClassObjectsWithImproperDataFormatProvider() public static function traitUsingClassObjectsAndBuiltCoderClassesProvider() { return array( - array(new DummyClassFormat1Encoder(), self::DUMMY_CODERS_NAMESPACE . '\Format1DataEncoder'), - array(new DummyClassFormat1Decoder(), self::DUMMY_CODERS_NAMESPACE . '\Format1DataDecoder'), - array(new DummyClassFormat2Encoder(), self::DUMMY_CODERS_NAMESPACE . '\Format2DataEncoder'), - array(new DummyClassFormat2Decoder(), self::DUMMY_CODERS_NAMESPACE . '\Format2DataDecoder'), - array(new Format1DummyClassEncoder(), self::DUMMY_CODERS_NAMESPACE . '\Format1DataEncoder'), - array(new Format1DummyClassDecoder(), self::DUMMY_CODERS_NAMESPACE . '\Format1DataDecoder'), - array(new Format2DummyClassEncoder(), self::DUMMY_CODERS_NAMESPACE . '\Format2DataEncoder'), - array(new Format2DummyClassDecoder(), self::DUMMY_CODERS_NAMESPACE . '\Format2DataDecoder'), + // Classes with explicitly defined dataFormat + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormat1Encoder')(), self::CODERS_NAMESPACE . '\Format1\Data\Encoder'), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormat1Decoder')(), self::CODERS_NAMESPACE . '\Format1\Data\Decoder'), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormat2Encoder')(), self::CODERS_NAMESPACE . '\Format2\Data\Encoder'), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\DummyClassFormat2Decoder')(), self::CODERS_NAMESPACE . '\Format2\Data\Decoder'), + // Classes with no explicitly defined dataFormat (it's established from the class name first part) + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\Format1DummyClassEncoder')(), self::CODERS_NAMESPACE . '\Format1\Data\Encoder'), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\Format1DummyClassDecoder')(), self::CODERS_NAMESPACE . '\Format1\Data\Decoder'), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\Format2DummyClassEncoder')(), self::CODERS_NAMESPACE . '\Format2\Data\Encoder'), + array(new (self::CODER_BUILDING_TRAIT_USING_CODERS_NAMESPACE . '\Format2DummyClassDecoder')(), self::CODERS_NAMESPACE . '\Format2\Data\Decoder'), ); } } diff --git a/tests/unit_tests/coder_builder/CoderClassNotFoundExceptionTest.php b/tests/unit_tests/CoderBuilder/CoderClassNotFoundExceptionTest.php similarity index 72% rename from tests/unit_tests/coder_builder/CoderClassNotFoundExceptionTest.php rename to tests/unit_tests/CoderBuilder/CoderClassNotFoundExceptionTest.php index cc1f838..742d192 100644 --- a/tests/unit_tests/coder_builder/CoderClassNotFoundExceptionTest.php +++ b/tests/unit_tests/CoderBuilder/CoderClassNotFoundExceptionTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder; use PHPUnit\Framework\TestCase; @@ -25,14 +25,16 @@ */ class CoderClassNotFoundExceptionTest extends TestCase { + const CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\CoderBuilder\CoderClassNotFoundException'; + /** - * Test if Exorg\DataCoder\CoderClassNotFoundException class + * Test if ExOrg\DataCoder\CoderClassNotFoundException class * has been created. */ public function testCoderClassNotFoundExceptionClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\CoderClassNotFoundException') + class_exists(self::CODER_CLASS_NOT_FOUND_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME) ); } } diff --git a/tests/unit_tests/data_format/DataFormatInvalidExceptionTest.php b/tests/unit_tests/DataFormat/DataFormatInvalidExceptionTest.php similarity index 82% rename from tests/unit_tests/data_format/DataFormatInvalidExceptionTest.php rename to tests/unit_tests/DataFormat/DataFormatInvalidExceptionTest.php index 39ae77f..54f44a5 100644 --- a/tests/unit_tests/data_format/DataFormatInvalidExceptionTest.php +++ b/tests/unit_tests/DataFormat/DataFormatInvalidExceptionTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\DataFormat; use PHPUnit\Framework\TestCase; @@ -26,13 +26,13 @@ class DataFormatInvalidExceptionTest extends TestCase { /** - * Test if Exorg\DataCoder\DataFormatInvalidException class + * Test if ExOrg\DataCoder\DataFormatInvalidException class * has been created. */ public function testDataFormatInvalidExceptionClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DataFormatInvalidException') + class_exists('ExOrg\DataCoder\DataFormat\DataFormatInvalidException') ); } } diff --git a/tests/unit_tests/data_format/DataFormatTest.php b/tests/unit_tests/DataFormat/DataFormatTest.php similarity index 80% rename from tests/unit_tests/data_format/DataFormatTest.php rename to tests/unit_tests/DataFormat/DataFormatTest.php index de317a2..b18e639 100644 --- a/tests/unit_tests/data_format/DataFormatTest.php +++ b/tests/unit_tests/DataFormat/DataFormatTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\DataFormat; use PHPUnit\Framework\TestCase; /** - * DataFormatTest. + * DataFormat Test. * PHPUnit test class for DataFormat class. * * @package DataCoder @@ -25,14 +25,16 @@ */ class DataFormatTest extends TestCase { + const DATA_FORMAT_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\DataFormat\DataFormat'; + /** - * Test Exorg\DatafilesParser\DataFormat enum + * Test ExOrg\DatafilesParser\DataFormat enum * has been implemented. */ public function testDataFormatExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DataFormat') + class_exists(self::DATA_FORMAT_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -47,7 +49,7 @@ class_exists('Exorg\DataCoder\DataFormat') */ public function testDataFormatsItems($formatAbbreviation, $expectedFormatFullName) { - $actualFormatFullName = constant("Exorg\DataCoder\DataFormat::$formatAbbreviation"); + $actualFormatFullName = constant(self::DATA_FORMAT_FULLY_QUALIFIED_CLASS_NAME . "::" . $formatAbbreviation); $this->assertEquals($expectedFormatFullName, $actualFormatFullName); } diff --git a/tests/unit_tests/file/FileExceptionTest.php b/tests/unit_tests/File/FileExceptionTest.php similarity index 73% rename from tests/unit_tests/file/FileExceptionTest.php rename to tests/unit_tests/File/FileExceptionTest.php index 4879259..b88d777 100644 --- a/tests/unit_tests/file/FileExceptionTest.php +++ b/tests/unit_tests/File/FileExceptionTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\File; use PHPUnit\Framework\TestCase; /** - * FileExceptionTest. + * FileException Test. * PHPUnit test class for FileException class. * * @package DataCoder @@ -25,14 +25,16 @@ */ class FileExceptionTest extends TestCase { + const FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\File\FileException'; + /** - * Test if Exorg\DataCoder\NonexistentFileException class + * Test if ExOrg\DataCoder\NonexistentFileException class * has been created. */ public function testFileExceptionTestClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\FileException') + class_exists(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME) ); } } diff --git a/tests/unit_tests/file/FileTest.php b/tests/unit_tests/File/FileTest.php similarity index 91% rename from tests/unit_tests/file/FileTest.php rename to tests/unit_tests/File/FileTest.php index c6695a9..961f5ed 100644 --- a/tests/unit_tests/file/FileTest.php +++ b/tests/unit_tests/File/FileTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\File; use PHPUnit\Framework\TestCase; /** - * FileTest. + * File Test. * PHPUnit test class for File class. * * @package DataCoder @@ -29,7 +29,10 @@ class FileTest extends TestCase * Relative path of directory with file fixtures * used in tests. */ - const FILE_FIXTURES_RELATIVE_PATH = '../../testing_environment/files'; + const FILE_FIXTURES_RELATIVE_PATH = '../../fixtures/files'; + + const FILE_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\File\File'; + const FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\File\FileException'; /** * Self-test for function buildFileFixturePath. @@ -46,13 +49,13 @@ public function testSelfBuildFileFixturePath() } /** - * Test if Exorg\DataCoder\File class + * Test if File class * has been created. */ public function testFileClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\File') + class_exists(self::FILE_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -106,7 +109,7 @@ public function testConstructorWhenFileDoesNotExist() $file = new File($filePath); - $this->assertInstanceOf('Exorg\DataCoder\File', $file); + $this->assertInstanceOf(self::FILE_FULLY_QUALIFIED_CLASS_NAME, $file); } /** @@ -119,7 +122,7 @@ public function testConstructorWhenFileExists() $file = new File($filePath); - $this->assertInstanceOf('Exorg\DataCoder\File', $file); + $this->assertInstanceOf(self::FILE_FULLY_QUALIFIED_CLASS_NAME, $file); } /** @@ -130,7 +133,7 @@ public function testGetExtensionFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\File', + self::FILE_FULLY_QUALIFIED_CLASS_NAME, 'getExtension' ) ); @@ -157,7 +160,7 @@ public function testGetContentFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\File', + self::FILE_FULLY_QUALIFIED_CLASS_NAME, 'getContent' ) ); @@ -169,7 +172,7 @@ public function testGetContentFunctionExists() */ public function testGetContentWhenFileDoesNotExist() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $filePath = self::buildFileFixturePath('nonexistent'); @@ -184,7 +187,7 @@ public function testGetContentWhenFileDoesNotExist() */ public function testGetContentWhenFileIsNotReadable() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $filePath = self::buildFileFixturePath('unreadable-file'); @@ -199,7 +202,7 @@ public function testGetContentWhenFileIsNotReadable() */ public function testGetContentWhenDirectoryIsNotReadable() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $filePath = self::buildFileFixturePath('unreadable-directory/file-for-read'); @@ -229,7 +232,7 @@ public function testSetContentFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\File', + self::FILE_FULLY_QUALIFIED_CLASS_NAME, 'setContent' ) ); @@ -256,7 +259,7 @@ public function testSetContentWhenContentIsImproper($content) */ public function testSetContentWhenFileIsNotWritable() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $filePath = self::buildFileFixturePath('unwritable-file'); @@ -271,7 +274,7 @@ public function testSetContentWhenFileIsNotWritable() */ public function testSetContentWhenDirectoryIsNotWritable() { - $this->expectException('\Exorg\DataCoder\FileException'); + $this->expectException(self::FILE_EXCEPTION_FULLY_QUALIFIED_CLASS_NAME); $filePath = self::buildFileFixturePath('unwritable-directory/file-for-write'); diff --git a/tests/testing_environment/helpers/DataFileFixturesHelper.php b/tests/unit_tests/Fixture/DataFileFixturesHelper.php similarity index 97% rename from tests/testing_environment/helpers/DataFileFixturesHelper.php rename to tests/unit_tests/Fixture/DataFileFixturesHelper.php index 64edfa9..59f2b63 100644 --- a/tests/testing_environment/helpers/DataFileFixturesHelper.php +++ b/tests/unit_tests/Fixture/DataFileFixturesHelper.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Fixture; /** - * DataFileFixturesHelper. + * Data File Fixtures Helper. * Helps to handle data file fixtures. * * @package DataCoder @@ -29,7 +29,7 @@ class DataFileFixturesHelper * They are inputs and the expected results * of the encoding/decoding operations. */ - const FILES_DIRECTORY = '../data'; + const FILES_DIRECTORY = '../../fixtures/data'; /** * Directory with the files containing encoded data diff --git a/tests/testing_environment/helpers/DataFileFixturesHelperTest.php b/tests/unit_tests/Fixture/DataFileFixturesHelperTest.php similarity index 79% rename from tests/testing_environment/helpers/DataFileFixturesHelperTest.php rename to tests/unit_tests/Fixture/DataFileFixturesHelperTest.php index 48ef5ae..3c5cc57 100644 --- a/tests/testing_environment/helpers/DataFileFixturesHelperTest.php +++ b/tests/unit_tests/Fixture/DataFileFixturesHelperTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Exorg\DataCoder; +namespace ExOrg\DataCoder\Fixture; use PHPUnit\Framework\TestCase; /** - * DataFileFixturesHelperTest. + * Data File Fixtures Helper Test. * PHPUnit base test class for * DataFileFixturesHelper. * @@ -26,6 +26,16 @@ */ class DataFileFixturesHelperTest extends TestCase { + const DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME = 'ExOrg\DataCoder\Fixture\DataFileFixturesHelper'; + + /** + * Directory with the files containing data + * in various formats. + * They are inputs and the expected results + * of the encoding/decoding operations. + */ + const FILES_DIRECTORY = '../../fixtures/data'; + /** * Instance of tested class. * @@ -34,13 +44,13 @@ class DataFileFixturesHelperTest extends TestCase private $dataFileFixturesHelper = null; /** - * Test if Exorg\DataCoder\DataFileFixturesHelper class + * Test if ExOrg\DataCoder\Fixture\DataFileFixturesHelper class * has been created. */ public function testDataCodersTestHelperClassExists() { $this->assertTrue( - class_exists('Exorg\DataCoder\DataFileFixturesHelper') + class_exists(self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME) ); } @@ -52,7 +62,7 @@ public function testSetDataFormatFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataFileFixturesHelper', + self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME, 'setDataFormat' ) ); @@ -66,7 +76,7 @@ public function testLoadEncodedDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataFileFixturesHelper', + self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME, 'loadEncodedData' ) ); @@ -106,7 +116,7 @@ public function testLoadDecodedDataFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataFileFixturesHelper', + self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME, 'loadDecodedData' ) ); @@ -148,7 +158,7 @@ public function testBuildEncodedFilePathFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataFileFixturesHelper', + self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME, 'buildEncodedFilePath' ) ); @@ -160,7 +170,7 @@ public function testBuildEncodedFilePathFunctionExists() */ public function testBuildEncodedFilePath() { - $expectedPath = realpath(__DIR__ . '/../data/encoded/data.self-test'); + $expectedPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . self::FILES_DIRECTORY . '/encoded/data.self-test'); $actualPath = $this->dataFileFixturesHelper->buildEncodedFilePath('data.self-test'); $this->assertEquals($expectedPath, $actualPath); @@ -174,7 +184,7 @@ public function testBuildDecodedFilePathFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataFileFixturesHelper', + self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME, 'buildDecodedFilePath' ) ); @@ -186,7 +196,7 @@ public function testBuildDecodedFilePathFunctionExists() */ public function testBuildDecodedFilePath() { - $expectedPath = realpath(__DIR__ . '/../data/decoded/self-test.php'); + $expectedPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . self::FILES_DIRECTORY . '/decoded/self-test.php'); $actualPath = $this->dataFileFixturesHelper->buildDecodedFilePath('self-test.php'); $this->assertEquals($expectedPath, $actualPath); @@ -200,7 +210,7 @@ public function testBuildCreatedFilePathFunctionExists() { $this->assertTrue( method_exists( - 'Exorg\DataCoder\DataFileFixturesHelper', + self::DATAFILE_FIXTURES_HELPER_FULLY_QUALIFIED_CLASS_NAME, 'buildCreatedFilePath' ) ); @@ -212,7 +222,7 @@ public function testBuildCreatedFilePathFunctionExists() */ public function testBuildCreatedFilePath() { - $expectedPath = realpath(__DIR__ . '/../data/created/') . DIRECTORY_SEPARATOR . 'self-test'; + $expectedPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . self::FILES_DIRECTORY . '/created/') . DIRECTORY_SEPARATOR . 'self-test'; $actualPath = $this->dataFileFixturesHelper->buildCreatedFilePath('self-test'); $this->assertEquals($expectedPath, $actualPath); @@ -235,7 +245,7 @@ protected function setUp(): void */ private function writeContentToSelfTestEncodedFile($content) { - $filePath = __DIR__ . "/../data/encoded/data.self-test"; + $filePath = __DIR__ . DIRECTORY_SEPARATOR . self::FILES_DIRECTORY . '/encoded/data.self-test'; file_put_contents($filePath, $content); } @@ -253,7 +263,7 @@ private function writeResultToSelfTestDecodedFile($result) } $content .= ');'; - $filePath = __DIR__ . "/../data/decoded/self-test.php"; + $filePath = __DIR__ . DIRECTORY_SEPARATOR . self::FILES_DIRECTORY . '/decoded/self-test.php'; file_put_contents($filePath, $content); } }