Skip to content

Commit

Permalink
Merge pull request #1 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 efe18de + 5646d98 commit b1cf2bf
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 53 deletions.
13 changes: 3 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
"name": "pre/immutable-classes",
"license": "MIT",
"require": {
"pre/plugin": "^0.7.3"
"pre/plugin": "^0.10.0"
},
"autoload": {
"psr-4": {
"Pre\\ImmutableClasses\\": "src"
"Pre\\ImmutableClasses\\": "source"
}
},
"require-dev": {
"phpunit/phpunit": "^5.0|^6.0"
},
"autoload-dev": {
"psr-4": {
"Pre\\ImmutableClasses\\": "tests"
}
},
"extra": {
"macros": [
"src/macros.yay"
]
"macros": ["source/macros.yay"]
}
}
2 changes: 1 addition & 1 deletion 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 Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/macros.yay → source/macros.yay
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ macro {
}
}

macro {
macro ·unsafe {
function __call(···parameters) {
immutability;
···body
Expand Down
42 changes: 36 additions & 6 deletions tests/MacroTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
<?php

namespace Pre\ImmutableClasses;
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/fallbacks.spec",
__DIR__ . "/specs/immutability.spec",
];

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

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

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

This file was deleted.

12 changes: 3 additions & 9 deletions tests/specs/fallbacks.spec
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
--DESCRIPTION--

Test immutability fallbacks

--GIVEN--

immutable class MyImmutableClass
{
public function __call($method, $parameters)
Expand All @@ -14,16 +8,16 @@ immutable class MyImmutableClass
}
}

--EXPECT--
~~~

class MyImmutableClass
{
use \Pre\ImmutableClasses\ImmutableClassesTrait;

public function __call($method, $parameters)
{
if ($result·1 = $this->handleCallImmutableClassSetters($method, $parameters)) {
return $result·1;
if ($result = $this->handleCallImmutableClassSetters($method, $parameters)) {
return $result;
}

print "fallback";
Expand Down
10 changes: 2 additions & 8 deletions tests/specs/immutability.spec
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
--DESCRIPTION--

Test immutability

--GIVEN--

immutable class MyImmutableClass
{
// nothign to see here
// nothing to see here
}

--EXPECT--
~~~

class MyImmutableClass
{
Expand Down

0 comments on commit b1cf2bf

Please sign in to comment.