diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a61a3ab --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.{diff,md}] +trim_trailing_whitespace = false + +[*.{php,xml,json}] +indent_size = 4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e925005 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: PHP Tests + +on: push + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + php: [7.3, 7.4, 8.0, 8.1] + + name: 'PHP ${{ matrix.php }}' + steps: + - uses: actions/checkout@master + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + extensions: curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip + tools: phpunit, composer:v2 + ini-values: display_errors=E_ALL + + - name: Install Composer dependencies + run: composer install + + - name: Run Composer tests + run: composer test diff --git a/.gitignore b/.gitignore index c6200b9..f396502 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ phpmd.xml .idea tests/tmp/* !tests/tmp/.gitkeep +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index a9ce77d..4b5b5b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,13 +12,10 @@ language: php matrix: include: - - php: 5.6 - env: CHECKS=yes PU4=yes - - php: 7.0 - - php: 7.1 - - php: 7.2 - php: 7.3 - php: 7.4 + - php: 8.0 + - php: 8.1 sudo: false diff --git a/LICENSE b/LICENSE index b6df720..a0a9c5a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Oleg Grigoriev +Copyright (c) 2022 Sami Mazouz Copyright (c) 2015 Oleg Grigoriev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d8a88da..32da241 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ The library for work with Source Map files from PHP. [![Latest Stable Version](https://img.shields.io/packagist/v/axy/sourcemap.svg?style=flat-square)](https://packagist.org/packages/axy/sourcemap) -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.4-8892BF.svg?style=flat-square)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg?style=flat-square)](https://php.net/) [![Build Status](https://img.shields.io/travis/axypro/sourcemap/master.svg?style=flat-square)](https://travis-ci.org/axypro/sourcemap) [![Coverage Status](https://coveralls.io/repos/axypro/sourcemap/badge.svg?branch=master&service=github)](https://coveralls.io/github/axypro/sourcemap?branch=master) [![License](https://poser.pugx.org/axy/sourcemap/license)](LICENSE) diff --git a/composer.json b/composer.json index 8ae3f02..4515bac 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,27 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=7.3", "ext-json": "*", - "axy/errors": "~1.0.1", - "axy/codecs-base64vlq": "~1.0.0" + "axy/errors": "^3.0", + "axy/codecs-base64vlq": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" }, "autoload": { "psr-4": { - "axy\\sourcemap\\": "" + "axy\\sourcemap\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "axy\\sourcemap\\tests\\": "tests/" + } + }, + "scripts": { + "test": "phpunit -c phpunit.xml.dist", + "md": "phpmd --exclude vendor . text phpmd.xml.dist", + "cs": "phpcs --standard=PSR2 --encoding=utf-8 --ignore=vendor ." } } diff --git a/cs.sh b/cs.sh old mode 100755 new mode 100644 index 7f2a1c1..596881e --- a/cs.sh +++ b/cs.sh @@ -1,4 +1,3 @@ #!/usr/bin/env sh /usr/bin/env phpcs --standard=PSR2 --encoding=utf-8 --ignore=vendor . - diff --git a/index.php b/index.php deleted file mode 100644 index 7c3c15f..0000000 --- a/index.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @license https://raw.github.com/axypro/sourcemap/master/LICENSE MIT - * @link https://github.com/axypro/sourcemap repository - * @link https://packagist.org/packages/axy/sourcemap composer - * @link https://github.com/axypro/sourcemap/blob/master/README.md documentation - * @uses PHP5.4+ - */ - -namespace axy\sourcemap; - -if (!is_file(__DIR__.'/vendor/autoload.php')) { - throw new \LogicException('Please: composer install'); -} - -require_once(__DIR__.'/vendor/autoload.php'); diff --git a/phpmd.sh b/phpmd.sh old mode 100755 new mode 100644 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 33f0660..f155fd5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,8 @@ - - - - ./tests/ - - - - - - ./vendor/ - - + + + ./src + + + + + ./tests/ + + diff --git a/PosGenerated.php b/src/PosGenerated.php similarity index 100% rename from PosGenerated.php rename to src/PosGenerated.php diff --git a/PosMap.php b/src/PosMap.php similarity index 100% rename from PosMap.php rename to src/PosMap.php diff --git a/PosSource.php b/src/PosSource.php similarity index 100% rename from PosSource.php rename to src/PosSource.php diff --git a/SourceMap.php b/src/SourceMap.php similarity index 100% rename from SourceMap.php rename to src/SourceMap.php diff --git a/errors/Error.php b/src/errors/Error.php similarity index 100% rename from errors/Error.php rename to src/errors/Error.php diff --git a/errors/IOError.php b/src/errors/IOError.php similarity index 100% rename from errors/IOError.php rename to src/errors/IOError.php diff --git a/errors/IncompleteData.php b/src/errors/IncompleteData.php similarity index 100% rename from errors/IncompleteData.php rename to src/errors/IncompleteData.php diff --git a/errors/InvalidFormat.php b/src/errors/InvalidFormat.php similarity index 100% rename from errors/InvalidFormat.php rename to src/errors/InvalidFormat.php diff --git a/errors/InvalidIndexed.php b/src/errors/InvalidIndexed.php similarity index 100% rename from errors/InvalidIndexed.php rename to src/errors/InvalidIndexed.php diff --git a/errors/InvalidJSON.php b/src/errors/InvalidJSON.php similarity index 100% rename from errors/InvalidJSON.php rename to src/errors/InvalidJSON.php diff --git a/errors/InvalidMappings.php b/src/errors/InvalidMappings.php similarity index 100% rename from errors/InvalidMappings.php rename to src/errors/InvalidMappings.php diff --git a/errors/InvalidSection.php b/src/errors/InvalidSection.php similarity index 100% rename from errors/InvalidSection.php rename to src/errors/InvalidSection.php diff --git a/errors/OutFileNotSpecified.php b/src/errors/OutFileNotSpecified.php similarity index 100% rename from errors/OutFileNotSpecified.php rename to src/errors/OutFileNotSpecified.php diff --git a/errors/UnsupportedVersion.php b/src/errors/UnsupportedVersion.php similarity index 100% rename from errors/UnsupportedVersion.php rename to src/errors/UnsupportedVersion.php diff --git a/helpers/IO.php b/src/helpers/IO.php similarity index 100% rename from helpers/IO.php rename to src/helpers/IO.php diff --git a/helpers/MapBuilder.php b/src/helpers/MapBuilder.php similarity index 100% rename from helpers/MapBuilder.php rename to src/helpers/MapBuilder.php diff --git a/helpers/PosBuilder.php b/src/helpers/PosBuilder.php similarity index 100% rename from helpers/PosBuilder.php rename to src/helpers/PosBuilder.php diff --git a/indexed/Base.php b/src/indexed/Base.php similarity index 100% rename from indexed/Base.php rename to src/indexed/Base.php diff --git a/indexed/Names.php b/src/indexed/Names.php similarity index 100% rename from indexed/Names.php rename to src/indexed/Names.php diff --git a/indexed/Sources.php b/src/indexed/Sources.php similarity index 100% rename from indexed/Sources.php rename to src/indexed/Sources.php diff --git a/parents/Base.php b/src/parents/Base.php similarity index 100% rename from parents/Base.php rename to src/parents/Base.php diff --git a/parents/Interfaces.php b/src/parents/Interfaces.php similarity index 68% rename from parents/Interfaces.php rename to src/parents/Interfaces.php index d8c25bd..3425dee 100644 --- a/parents/Interfaces.php +++ b/src/parents/Interfaces.php @@ -6,6 +6,8 @@ namespace axy\sourcemap\parents; +use Traversable; + /** * Partition of the SourceMap class (interfaces implementations) */ @@ -14,7 +16,7 @@ abstract class Interfaces extends Magic implements \IteratorAggregate, \ArrayAcc /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->getData()); } @@ -22,7 +24,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return $this->__isset($offset); } @@ -30,6 +32,7 @@ public function offsetExists($offset) /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->__get($offset); @@ -38,7 +41,7 @@ public function offsetGet($offset) /** * {@inheritdoc} */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $this->__set($offset, $value); } @@ -46,7 +49,7 @@ public function offsetSet($offset, $value) /** * {@inheritdoc} */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { $this->__unset($offset); } @@ -54,6 +57,7 @@ public function offsetUnset($offset) /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->getData(); @@ -64,9 +68,7 @@ public function jsonSerialize() */ public function serialize() { - $data = $this->getData(); - $data['mappings_serialized'] = $this->context->getMappings(); - return serialize($data); + return serialize($this->__serialize()); } /** @@ -76,4 +78,22 @@ public function unserialize($serialized) { $this->__construct(unserialize($serialized)); } + + /** + * {@inheritdoc} + */ + public function __serialize(): array + { + $data = $this->getData(); + $data['mappings_serialized'] = $this->context->getMappings(); + return $data; + } + + /** + * {@inheritdoc} + */ + public function __unserialize(array $serialized): void + { + $this->__construct($serialized); + } } diff --git a/parents/Magic.php b/src/parents/Magic.php similarity index 98% rename from parents/Magic.php rename to src/parents/Magic.php index 0766e4a..3bd1d92 100644 --- a/parents/Magic.php +++ b/src/parents/Magic.php @@ -118,7 +118,7 @@ public function __toString() /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->getData()); } diff --git a/parsing/Context.php b/src/parsing/Context.php similarity index 100% rename from parsing/Context.php rename to src/parsing/Context.php diff --git a/parsing/FormatChecker.php b/src/parsing/FormatChecker.php similarity index 100% rename from parsing/FormatChecker.php rename to src/parsing/FormatChecker.php diff --git a/parsing/Line.php b/src/parsing/Line.php similarity index 100% rename from parsing/Line.php rename to src/parsing/Line.php diff --git a/parsing/Mappings.php b/src/parsing/Mappings.php similarity index 100% rename from parsing/Mappings.php rename to src/parsing/Mappings.php diff --git a/parsing/SegmentParser.php b/src/parsing/SegmentParser.php similarity index 100% rename from parsing/SegmentParser.php rename to src/parsing/SegmentParser.php diff --git a/tests/PosMapTest.php b/tests/PosMapTest.php index a001ada..15be017 100644 --- a/tests/PosMapTest.php +++ b/tests/PosMapTest.php @@ -13,7 +13,7 @@ /** * coversDefaultClass axy\sourcemap\PosMap */ -class PosMapTest extends \PHPUnit_Framework_TestCase +class PosMapTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct @@ -116,11 +116,13 @@ public function providerCreate() /** * covers ::__construct - * @expectedException \InvalidArgumentException + * * @return \axy\sourcemap\PosMap */ public function testCreateInvalidArgument() { + $this->expectException(\InvalidArgumentException::class); + return new PosMap(3); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 4a9b61b..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,9 +0,0 @@ - - */ - -namespace axy\sourcemap\tests; - -require(__DIR__.'/../index.php'); diff --git a/tests/classSourceMap/AddTest.php b/tests/classSourceMap/AddTest.php index 198e17c..048e248 100644 --- a/tests/classSourceMap/AddTest.php +++ b/tests/classSourceMap/AddTest.php @@ -6,6 +6,8 @@ namespace axy\sourcemap\tests\classSourceMap; +use axy\sourcemap\errors\IncompleteData; +use axy\sourcemap\errors\InvalidIndexed; use axy\sourcemap\SourceMap; use axy\sourcemap\PosMap; use axy\sourcemap\PosGenerated; @@ -15,7 +17,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class AddTest extends \PHPUnit_Framework_TestCase +class AddTest extends \PHPUnit\Framework\TestCase { /** * @var array @@ -37,7 +39,7 @@ class AddTest extends \PHPUnit_Framework_TestCase /** * {@inheritdoc} */ - public function setUp() + public function setUp(): void { $this->map = new SourceMap($this->data); } @@ -156,8 +158,9 @@ public function testAddPositionArray() public function testErrorIncompleteData($position, $error = true) { if ($error) { - $this->setExpectedException('axy\sourcemap\errors\IncompleteData'); + $this->expectException(IncompleteData::class); } + $this->map->addPosition($position); } @@ -221,7 +224,7 @@ public function providerErrorIncompleteData() public function testErrorInvalidIndexed($position, $error = true) { if ($error) { - $this->setExpectedException('axy\sourcemap\errors\InvalidIndexed'); + $this->expectException(InvalidIndexed::class); } $this->map->addPosition($position); } diff --git a/tests/classSourceMap/BlockTest.php b/tests/classSourceMap/BlockTest.php index 67e2a2f..7b638d4 100644 --- a/tests/classSourceMap/BlockTest.php +++ b/tests/classSourceMap/BlockTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class BlockTest extends \PHPUnit_Framework_TestCase +class BlockTest extends \PHPUnit\Framework\TestCase { /** * @var array @@ -40,7 +40,7 @@ class BlockTest extends \PHPUnit_Framework_TestCase /** * {@inheritdoc} */ - public function setUp() + public function setUp(): void { $this->posList = []; $this->map = new SourceMap(); diff --git a/tests/classSourceMap/ChangeTest.php b/tests/classSourceMap/ChangeTest.php index 40b0088..6861362 100644 --- a/tests/classSourceMap/ChangeTest.php +++ b/tests/classSourceMap/ChangeTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class ChangeTest extends \PHPUnit_Framework_TestCase +class ChangeTest extends \PHPUnit\Framework\TestCase { public function testFileRename() { diff --git a/tests/classSourceMap/CloneTest.php b/tests/classSourceMap/CloneTest.php index c06c384..1a52fd8 100644 --- a/tests/classSourceMap/CloneTest.php +++ b/tests/classSourceMap/CloneTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class CloneTest extends \PHPUnit_Framework_TestCase +class CloneTest extends \PHPUnit\Framework\TestCase { /** * covers ::__clone diff --git a/tests/classSourceMap/CommonTest.php b/tests/classSourceMap/CommonTest.php index e4f56ed..88a229b 100644 --- a/tests/classSourceMap/CommonTest.php +++ b/tests/classSourceMap/CommonTest.php @@ -6,12 +6,17 @@ namespace axy\sourcemap\tests\classSourceMap; +use axy\sourcemap\errors\InvalidFormat; +use axy\sourcemap\errors\InvalidJSON; +use axy\sourcemap\errors\IOError; +use axy\sourcemap\errors\OutFileNotSpecified; +use axy\sourcemap\errors\UnsupportedVersion; use axy\sourcemap\SourceMap; /** * coversDefaultClass axy\sourcemap\SourceMap */ -class CommonTest extends \PHPUnit_Framework_TestCase +class CommonTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct @@ -30,7 +35,7 @@ public function testCreate() 'mappings' => '', ]; $this->assertEquals($expected, $map->getData()); - $this->setExpectedException('axy\sourcemap\errors\InvalidFormat'); + $this->expectException(InvalidFormat::class); return new SourceMap(['version' => 5]); } @@ -78,31 +83,37 @@ public function testLoadFromFile() /** * covers ::loadFromFile - * @expectedException \axy\sourcemap\errors\IOError + * * @return \axy\sourcemap\SourceMap */ public function testLoadFromFileNotFound() { + $this->expectException(IOError::class); + return SourceMap::loadFromFile(__DIR__.'/../tst/notFound.js.map'); } /** * covers ::loadFromFile - * @expectedException \axy\sourcemap\errors\InvalidJSON + * * @return \axy\sourcemap\SourceMap */ public function testLoadFromFileInvalidJSON() { + $this->expectException(InvalidJSON::class); + return SourceMap::loadFromFile(__DIR__.'/../tst/invalid.json.js.map'); } /** * covers ::loadFromFile - * @expectedException \axy\sourcemap\errors\UnsupportedVersion + * * @return \axy\sourcemap\SourceMap */ public function testLoadFromFileUnsupportedVersion() { + $this->expectException(UnsupportedVersion::class); + return SourceMap::loadFromFile(__DIR__.'/../tst/version4.js.map'); } @@ -127,7 +138,7 @@ public function testSave() $map->save($fn); $this->assertFileExists($fn); $this->assertEquals($data, json_decode(file_get_contents($fn), true)); - $this->setExpectedException('axy\sourcemap\errors\IOError', 'und/und.map'); + $this->expectException(IOError::class); $map->save(__DIR__.'/../tmp/und/und.map'); } @@ -163,7 +174,7 @@ public function testOutFileName() $this->assertSame('/root/js/', $json1['sourceRoot']); $this->assertSame('/root/js/', $json2['sourceRoot']); $map3->outFileName = null; - $this->setExpectedException('axy\sourcemap\errors\OutFileNotSpecified'); + $this->expectException(OutFileNotSpecified::class); $map3->save(); } } diff --git a/tests/classSourceMap/ConcatTest.php b/tests/classSourceMap/ConcatTest.php index 1e8dc3b..5cfabcf 100644 --- a/tests/classSourceMap/ConcatTest.php +++ b/tests/classSourceMap/ConcatTest.php @@ -6,13 +6,14 @@ namespace axy\sourcemap\tests\classSourceMap; +use axy\sourcemap\errors\InvalidJSON; use axy\sourcemap\SourceMap; use axy\sourcemap\tests\Represent; /** * coversDefaultClass axy\sourcemap\SourceMap */ -class ConcatTest extends \PHPUnit_Framework_TestCase +class ConcatTest extends \PHPUnit\Framework\TestCase { /** * covers ::concat @@ -253,10 +254,11 @@ public function testConcatLine() /** * covers ::concat * - * @expectedException \axy\sourcemap\errors\InvalidJSON + * */ public function testConcatInvalidFormat() { + $this->expectException(InvalidJSON::class); $map = new SourceMap(); $map->concat(__DIR__.'/../tst/invalid.json.js.map', 0); } diff --git a/tests/classSourceMap/InterfacesTest.php b/tests/classSourceMap/InterfacesTest.php index 333a186..096b173 100644 --- a/tests/classSourceMap/InterfacesTest.php +++ b/tests/classSourceMap/InterfacesTest.php @@ -6,12 +6,13 @@ namespace axy\sourcemap\tests\classSourceMap; +use axy\errors\ReadOnlyException; use axy\sourcemap\SourceMap; /** * coversDefaultClass axy\sourcemap\SourceMap */ -class InterfacesTest extends \PHPUnit_Framework_TestCase +class InterfacesTest extends \PHPUnit\Framework\TestCase { /** * @var array @@ -33,7 +34,7 @@ class InterfacesTest extends \PHPUnit_Framework_TestCase /** * {@inheritdoc} */ - public function setUp() + public function setUp(): void { $this->map = new SourceMap($this->data); } @@ -55,7 +56,7 @@ public function testArrayAccess() $this->map['file'] = 'out.js'; $this->assertSame('out.js', $this->map['file']); $this->assertSame('out.js', $this->map->file); - $this->setExpectedException('axy\errors\ReadOnly'); + $this->expectException(ReadOnlyException::class); unset($this->map['file']); } @@ -70,7 +71,7 @@ public function testSerializable() $structure = ['map' => $this->map]; $serialized = serialize($structure); $unSerialized = unserialize($serialized); - $this->assertInternalType('array', $unSerialized); + $this->assertIsArray($unSerialized); $this->assertArrayHasKey('map', $unSerialized); /** @var \axy\sourcemap\SourceMap $map2 */ $map2 = $unSerialized['map']; diff --git a/tests/classSourceMap/MagicTest.php b/tests/classSourceMap/MagicTest.php index fdbe223..99f07e3 100644 --- a/tests/classSourceMap/MagicTest.php +++ b/tests/classSourceMap/MagicTest.php @@ -6,12 +6,14 @@ namespace axy\sourcemap\tests\classSourceMap; +use axy\errors\PropertyReadOnly; +use axy\sourcemap\errors\UnsupportedVersion; use axy\sourcemap\SourceMap; /** * coversDefaultClass axy\sourcemap\SourceMap */ -class MagicTest extends \PHPUnit_Framework_TestCase +class MagicTest extends \PHPUnit\Framework\TestCase { public function testPropertyVersion() { @@ -21,7 +23,7 @@ public function testPropertyVersion() $map->version = 3; $map->version = '3'; $this->assertSame(3, $map->version); - $this->setExpectedException('axy\sourcemap\errors\UnsupportedVersion'); + $this->expectException(UnsupportedVersion::class); $map->version = 5; } @@ -62,36 +64,39 @@ public function testPropertySourcesNames() $this->assertInstanceOf('axy\sourcemap\indexed\Names', $map->names); $this->assertEquals(['a.js', 'b.js'], $map->sources->getNames()); $this->assertEquals(['one', 'two', 'three'], $map->names->getNames()); - $this->setExpectedException('axy\errors\PropertyReadOnly'); + $this->expectException(PropertyReadOnly::class); $map->__set('sources', ['c.js']); } /** * covers ::__get - * @expectedException \axy\errors\FieldNotExist + * */ public function testMagicGet() { + $this->expectException(\axy\errors\FieldNotExist::class); $map = new SourceMap(); $map->__get('abc'); } /** * covers ::__set - * @expectedException \axy\errors\FieldNotExist + * */ public function testMagicSet() { + $this->expectException(\axy\errors\FieldNotExist::class); $map = new SourceMap(); $map->__set('abc', 1); } /** * covers ::__unset - * @expectedException \axy\errors\ContainerReadOnly + * */ public function testMagicUnset() { + $this->expectException(\axy\errors\ContainerReadOnly::class); $map = new SourceMap(); unset($map->version); } diff --git a/tests/classSourceMap/MergeTest.php b/tests/classSourceMap/MergeTest.php index a8fc29a..0860f7f 100644 --- a/tests/classSourceMap/MergeTest.php +++ b/tests/classSourceMap/MergeTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class MergeTest extends \PHPUnit_Framework_TestCase +class MergeTest extends \PHPUnit\Framework\TestCase { /** * covers ::merge @@ -80,10 +80,11 @@ public function testMerge() /** * covers ::merge - * @expectedException \axy\sourcemap\errors\InvalidJSON + * */ public function testMergeInvalidFormat() { + $this->expectException(\axy\sourcemap\errors\InvalidJSON::class); $map = new SourceMap(); $map->merge(__DIR__.'/../tst/invalid.json.js.map'); } diff --git a/tests/classSourceMap/OptimizeTest.php b/tests/classSourceMap/OptimizeTest.php index 193aab7..7f2ea12 100644 --- a/tests/classSourceMap/OptimizeTest.php +++ b/tests/classSourceMap/OptimizeTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class OptimizeTest extends \PHPUnit_Framework_TestCase +class OptimizeTest extends \PHPUnit\Framework\TestCase { /** * covers ::optiomize diff --git a/tests/classSourceMap/SContentTest.php b/tests/classSourceMap/SContentTest.php index 775dcef..aa67c6d 100644 --- a/tests/classSourceMap/SContentTest.php +++ b/tests/classSourceMap/SContentTest.php @@ -8,7 +8,7 @@ use axy\sourcemap\SourceMap; -class SContentTest extends \PHPUnit_Framework_TestCase +class SContentTest extends \PHPUnit\Framework\TestCase { public function testSourceContentLoad() { diff --git a/tests/classSourceMap/SearchTest.php b/tests/classSourceMap/SearchTest.php index 80e7679..e33ff69 100644 --- a/tests/classSourceMap/SearchTest.php +++ b/tests/classSourceMap/SearchTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\SourceMap */ -class SearchTest extends \PHPUnit_Framework_TestCase +class SearchTest extends \PHPUnit\Framework\TestCase { /** * covers ::getPosition @@ -78,7 +78,7 @@ public function testFind() { $map = SourceMap::loadFromFile(__DIR__.'/../tst/app.js.map'); $all = $map->find(); - $this->assertInternalType('array', $all); + $this->assertIsArray($all); $this->assertCount(72, $all); $p23 = $all[23]; $this->assertInstanceOf('axy\sourcemap\PosMap', $p23); diff --git a/tests/errors/IOErrorTest.php b/tests/errors/IOErrorTest.php index 8249158..ca5bc31 100644 --- a/tests/errors/IOErrorTest.php +++ b/tests/errors/IOErrorTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\IOError */ -class IOErrorTest extends \PHPUnit_Framework_TestCase +class IOErrorTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/IncompleteDataTest.php b/tests/errors/IncompleteDataTest.php index 6c741ce..04837d9 100644 --- a/tests/errors/IncompleteDataTest.php +++ b/tests/errors/IncompleteDataTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\IncompleteData */ -class IncompleteDataTest extends \PHPUnit_Framework_TestCase +class IncompleteDataTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/InvalidIndexedTest.php b/tests/errors/InvalidIndexedTest.php index 2844dc0..1b06c3c 100644 --- a/tests/errors/InvalidIndexedTest.php +++ b/tests/errors/InvalidIndexedTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\InvalidIndexed */ -class InvalidIndexedTest extends \PHPUnit_Framework_TestCase +class InvalidIndexedTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/InvalidJSONTest.php b/tests/errors/InvalidJSONTest.php index dd39a13..3da0e83 100644 --- a/tests/errors/InvalidJSONTest.php +++ b/tests/errors/InvalidJSONTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\InvalidJSON */ -class InvalidJSONTest extends \PHPUnit_Framework_TestCase +class InvalidJSONTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/InvalidMappingsTest.php b/tests/errors/InvalidMappingsTest.php index 3a2519f..d3c965f 100644 --- a/tests/errors/InvalidMappingsTest.php +++ b/tests/errors/InvalidMappingsTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\InvalidMappings */ -class InvalidMappingsTest extends \PHPUnit_Framework_TestCase +class InvalidMappingsTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/InvalidSectionTest.php b/tests/errors/InvalidSectionTest.php index a23800a..fe03531 100644 --- a/tests/errors/InvalidSectionTest.php +++ b/tests/errors/InvalidSectionTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\InvalidSection */ -class InvalidSectionTest extends \PHPUnit_Framework_TestCase +class InvalidSectionTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/OutFileNotSpecifiedTest.php b/tests/errors/OutFileNotSpecifiedTest.php index cd23ee0..da249ad 100644 --- a/tests/errors/OutFileNotSpecifiedTest.php +++ b/tests/errors/OutFileNotSpecifiedTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\OutFileNotSpecifiedTest */ -class OutFileNotSpecifiedTest extends \PHPUnit_Framework_TestCase +class OutFileNotSpecifiedTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/errors/UnsupportedVersionTest.php b/tests/errors/UnsupportedVersionTest.php index 96a0ced..e32b242 100644 --- a/tests/errors/UnsupportedVersionTest.php +++ b/tests/errors/UnsupportedVersionTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\errors\UnsupportedVersion */ -class UnsupportedVersionTest extends \PHPUnit_Framework_TestCase +class UnsupportedVersionTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/helpers/IOTest.php b/tests/helpers/IOTest.php index 06d1826..0dafd7a 100644 --- a/tests/helpers/IOTest.php +++ b/tests/helpers/IOTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\helpers\IO */ -class IOTest extends \PHPUnit_Framework_TestCase +class IOTest extends \PHPUnit\Framework\TestCase { /** * covers ::load @@ -24,11 +24,13 @@ public function testLoad() /** * covers ::load - * @expectedException \axy\sourcemap\errors\IOError - * @expectedExceptionMessage not.found.js.map + * + * */ public function testLoadIOError() { + $this->expectExceptionMessage("not.found.js.map"); + $this->expectException(\axy\sourcemap\errors\IOError::class); IO::load(__DIR__.'/../not.found.js.map'); } @@ -49,11 +51,13 @@ public function testSave() /** * covers ::load - * @expectedException \axy\sourcemap\errors\IOError - * @expectedExceptionMessage tmp/und/und.txt + * + * */ public function testSaveIOError() { + $this->expectExceptionMessage("tmp/und/und.txt"); + $this->expectException(\axy\sourcemap\errors\IOError::class); $fn = __DIR__.'/../tmp/und/und.txt'; IO::save($fn, 'Content'); } diff --git a/tests/helpers/MapBuilderTest.php b/tests/helpers/MapBuilderTest.php index 8044497..97c4876 100644 --- a/tests/helpers/MapBuilderTest.php +++ b/tests/helpers/MapBuilderTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\helpers\MapsBuilder */ -class MapBuilderTest extends \PHPUnit_Framework_TestCase +class MapBuilderTest extends \PHPUnit\Framework\TestCase { /** * covers ::build @@ -28,7 +28,7 @@ public function testBuild($pointer, $file, $exception = null) $this->assertInstanceOf('axy\sourcemap\SourceMap', $map); $this->assertSame($file, $map->file); } else { - $this->setExpectedException($exception); + $this->expectException($exception); MapBuilder::build($pointer); } } @@ -63,17 +63,17 @@ public function providerBuild() [ __DIR__.'/../tst/notFound.js.map', null, - 'axy\sourcemap\errors\IOError', + \axy\sourcemap\errors\IOError::class, ], [ __DIR__.'/../tst/invalid.json.js.map', null, - 'axy\sourcemap\errors\InvalidFormat', + \axy\sourcemap\errors\InvalidFormat::class, ], [ 5, null, - 'InvalidArgumentException', + \InvalidArgumentException::class, ], ]; } diff --git a/tests/helpers/PosBuilderTest.php b/tests/helpers/PosBuilderTest.php index 9acccd9..f9697c9 100644 --- a/tests/helpers/PosBuilderTest.php +++ b/tests/helpers/PosBuilderTest.php @@ -13,7 +13,7 @@ /** * coversDefaultClass axy\sourcemap\helpers\PosBuilder */ -class PosBuilderTest extends \PHPUnit_Framework_TestCase +class PosBuilderTest extends \PHPUnit\Framework\TestCase { /** * covers ::build diff --git a/tests/indexed/BaseTest.php b/tests/indexed/BaseTest.php index 1a6897f..f943fa8 100644 --- a/tests/indexed/BaseTest.php +++ b/tests/indexed/BaseTest.php @@ -13,7 +13,7 @@ * coversDefaultClass axy\sourcemap\indexed\Base * Abstract class is tested using Names class */ -class BaseTest extends \PHPUnit_Framework_TestCase +class BaseTest extends \PHPUnit\Framework\TestCase { /** * @var array diff --git a/tests/indexed/NamesTest.php b/tests/indexed/NamesTest.php index 5347802..1746581 100644 --- a/tests/indexed/NamesTest.php +++ b/tests/indexed/NamesTest.php @@ -14,7 +14,7 @@ /** * coversDefaultClass axy\sourcemap\indexed\Names */ -class NamesTest extends \PHPUnit_Framework_TestCase +class NamesTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct @@ -129,7 +129,7 @@ public function testFillSource() // by name + index (fail) $source->nameIndex = 2; $source->name = 'one'; - $this->setExpectedException('axy\sourcemap\errors\InvalidIndexed'); + $this->expectException(\axy\sourcemap\errors\InvalidIndexed::class); $names->fillSource($source); } } diff --git a/tests/indexed/SourcesTest.php b/tests/indexed/SourcesTest.php index 14c38eb..a1f0750 100644 --- a/tests/indexed/SourcesTest.php +++ b/tests/indexed/SourcesTest.php @@ -15,7 +15,7 @@ /** * coversDefaultClass axy\sourcemap\indexed\Sources */ -class SourcesTest extends \PHPUnit_Framework_TestCase +class SourcesTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct @@ -128,7 +128,7 @@ public function testFillSource() // by name + index (fail) $source->fileIndex = 2; $source->fileName = 'a.js'; - $this->setExpectedException('axy\sourcemap\errors\InvalidIndexed'); + $this->expectException(\axy\sourcemap\errors\InvalidIndexed::class); $s->fillSource($source); } diff --git a/tests/parsing/ContextTest.php b/tests/parsing/ContextTest.php index 9423462..c75c0f0 100644 --- a/tests/parsing/ContextTest.php +++ b/tests/parsing/ContextTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\parsing\Context */ -class ContextTest extends \PHPUnit_Framework_TestCase +class ContextTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct diff --git a/tests/parsing/FormatCheckerTest.php b/tests/parsing/FormatCheckerTest.php index 3f0cd39..18e3b2e 100644 --- a/tests/parsing/FormatCheckerTest.php +++ b/tests/parsing/FormatCheckerTest.php @@ -11,7 +11,7 @@ /** * coversDefaultClass axy\sourcemap\parsing\FormatChecker */ -class FormatCheckerTest extends \PHPUnit_Framework_TestCase +class FormatCheckerTest extends \PHPUnit\Framework\TestCase { /** * covers ::check @@ -83,10 +83,11 @@ public function providerCheck() /** * covers ::check - * @expectedException \axy\sourcemap\errors\UnsupportedVersion + * */ public function testUnsupportedVersion() { + $this->expectException(\axy\sourcemap\errors\UnsupportedVersion::class); $data = [ 'version' => 5, 'sources' => ['a.js', 'b.js'], @@ -100,10 +101,11 @@ public function testUnsupportedVersion() * @dataProvider providerInvalidSection * @param array $data * @param array $data - * @expectedException \axy\sourcemap\errors\InvalidSection + * */ public function testInvalidSection(array $data) { + $this->expectException(\axy\sourcemap\errors\InvalidSection::class); FormatChecker::check($data); } diff --git a/tests/parsing/LineTest.php b/tests/parsing/LineTest.php index b9ee3b4..0e6f221 100644 --- a/tests/parsing/LineTest.php +++ b/tests/parsing/LineTest.php @@ -15,7 +15,7 @@ /** * coversDefaultClass axy\sourcemap\parsing\Line */ -class LineTest extends \PHPUnit_Framework_TestCase +class LineTest extends \PHPUnit\Framework\TestCase { /** * covers ::__construct @@ -182,11 +182,12 @@ public function testLoadFromMappings() /** * covers ::loadFromMappings * @dataProvider providerErrorLoad - * @expectedException \axy\sourcemap\errors\InvalidMappings + * * @param string $lMappings */ public function testErrorLoad($lMappings) { + $this->expectException(\axy\sourcemap\errors\InvalidMappings::class); $data = [ 'version' => 3, 'sources' => ['a.js', 'b.js'], diff --git a/tests/parsing/MappingsTest.php b/tests/parsing/MappingsTest.php index 90a2caf..6f3c4aa 100644 --- a/tests/parsing/MappingsTest.php +++ b/tests/parsing/MappingsTest.php @@ -14,7 +14,7 @@ /** * coversDefaultClass axy\sourcemap\parsing\Mappings */ -class MappingsTest extends \PHPUnit_Framework_TestCase +class MappingsTest extends \PHPUnit\Framework\TestCase { /** * @var array diff --git a/tests/parsing/SegmentParserTest.php b/tests/parsing/SegmentParserTest.php index 83c63b5..bd9a2c8 100644 --- a/tests/parsing/SegmentParserTest.php +++ b/tests/parsing/SegmentParserTest.php @@ -12,7 +12,7 @@ /** * coversDefaultClass axy\sourcemap\parsing\SegmentParser */ -class SegmentParserTest extends \PHPUnit_Framework_TestCase +class SegmentParserTest extends \PHPUnit\Framework\TestCase { /** * covers ::nextLine @@ -80,10 +80,11 @@ public function testParse() * covers ::parse * @dataProvider providerParseError * @param string $segment - * @expectedException \axy\sourcemap\errors\InvalidMappings + * */ public function testParseError($segment) { + $this->expectException(\axy\sourcemap\errors\InvalidMappings::class); $parser = new SegmentParser(); $parser->parse($segment); }