Skip to content

Commit

Permalink
Merge pull request #4 from preprocess/refactor-for-new-plugin
Browse files Browse the repository at this point in the history
Refactor for new plugin
  • Loading branch information
assertchris authored Oct 28, 2017
2 parents 64e0b42 + 1d38abb commit a888d04
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage
vendor
composer.lock
16 changes: 3 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
"name": "pre/collections",
"license": "MIT",
"require": {
"pre/plugin": "^0.7.3"
"pre/plugin": "^0.10.0"
},
"autoload": {
"files": [
"src/parsers.php"
],
"psr-4": {
"Pre\\Collections\\": "src"
"Pre\\Collections\\": "source"
}
},
"require-dev": {
"phpunit/phpunit": "^5.0|^6.0"
},
"autoload-dev": {
"psr-4": {
"Pre\\Collections\\": "tests"
}
},
"extra": {
"macros": [
"src/macros.yay"
]
"macros": ["source/macros.yay"]
}
}
7 changes: 2 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -18,10 +18,7 @@
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<file>src/parsers.php</file>
</exclude>
<directory suffix=".php">source</directory>
</whitelist>
</filter>
</phpunit>
File renamed without changes.
4 changes: 2 additions & 2 deletions src/macros.yay → source/macros.yay
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
macro ·recursion {
·chain(
·token("{"),
·angle_layer()·values,
·layer()·values,
·token("}"),
·token("="),
·_()·keys
Expand Down Expand Up @@ -48,7 +48,7 @@ macro ·recursion {
)
)·before,
·token("{"),
·optional(·angle_layer())·values,
·optional(·layer())·values,
·token("}"),
·_()·is_array,
·_()·is_not_array
Expand Down
15 changes: 0 additions & 15 deletions src/parsers.php

This file was deleted.

5 changes: 0 additions & 5 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

namespace Pre\Collections;

use ArrayIterator;
use InvalidArgumentException;
use Iterator;
use PHPUnit\Framework\TestCase;
use Pre\Collections\Collection;

Expand Down
41 changes: 35 additions & 6 deletions tests/MacroTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
<?php

namespace Pre\Collections;
use PHPUnit\Framework\TestCase;

use Pre\Plugin\Testing\Runner;

class MacroTest extends Runner
class MacroTest extends TestCase
{
protected function path(): string
/**
* @test
* @dataProvider specs
*/
public function can_transform_code($from, $expected)
{
Pre\Plugin\addMacro(__DIR__ . "/../source/macros.yay");

$actual = Pre\plugin\format(Pre\Plugin\parse($this->format($from)));
$this->assertEquals($this->format($expected), $actual);
}

private function format($code)
{
return __DIR__ . "/specs";
return "<?php\n\n" . trim($code) . "\n";
}

public static function specs()
{
$specs = [];

$files = [
__DIR__ . "/specs/collections.spec",
];

foreach ($files as $file) {
$contents = file_get_contents($file);

foreach (explode("---", $contents) as $spec) {
array_push($specs, explode("~~~", $spec));
}
}

return $specs;
}
}
7 changes: 0 additions & 7 deletions tests/bootstrap.php

This file was deleted.

8 changes: 1 addition & 7 deletions tests/specs/collections.spec
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
--DESCRIPTION--

Test collections macros

--GIVEN--

({});

[{}];
Expand Down Expand Up @@ -42,7 +36,7 @@ $d = {

["foo" => {"bar" => "baz"}]

--EXPECT--
~~~

( (new \Pre\Collections\Collection()));

Expand Down

0 comments on commit a888d04

Please sign in to comment.