Skip to content

Commit

Permalink
Refactor for new plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Oct 28, 2017
1 parent 35a02c5 commit c8b5c8a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 55 deletions.
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
"type": "pre-macro",
"name": "pre/async",
"license": "MIT",
"repositories": [
{
"type": "path",
"url": "../pre-plugin"
}
],
"require": {
"pre/plugin": "^0.7.3"
"pre/plugin": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.0|^6.0"
},
"autoload-dev": {
"psr-4": {
"Pre\\Async\\": "tests"
}
},
"extra": {
"macros": [
"src/macros.yay"
]
}
"macros": ["source/macros.yay"]
},
"minimum-stability": "dev",
"prefer-stable": true
}
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.
44 changes: 44 additions & 0 deletions tests/MacroTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use PHPUnit\Framework\TestCase;

putenv("PRE_BASE_DIR=" . realpath(__DIR__ . "/../"));

class MacroTest extends TestCase
{
/**
* @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 "<?php\n\n" . trim($code) . "\n";
}

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

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

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

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

return $specs;
}
}
13 changes: 0 additions & 13 deletions tests/SpecTest.php

This file was deleted.

7 changes: 0 additions & 7 deletions tests/bootstrap.php

This file was deleted.

50 changes: 26 additions & 24 deletions tests/specs/async.spec
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
--DESCRIPTION--

Test async macros
interface AsyncInterface
{
async public function run();
}

--GIVEN--
~~~

interface AsyncInterface
{
async public function run();
public function run(): \Amp\Promise;
}

---

class AsyncClass
{
async public function first(array $data = [])
Expand All @@ -27,25 +30,7 @@ class AsyncClass
}
}

$first = async function() {
yield "here";
};

$second = async function() {
$this->something();
yield $thing;
};

$third = async () => {
yield $thing;
};

--EXPECT--

interface AsyncInterface
{
public function run(): \Amp\Promise;
}
~~~

class AsyncClass
{
Expand All @@ -72,6 +57,23 @@ class AsyncClass
}
}

---

$first = async function() {
yield "here";
};

$second = async function() {
$this->something();
yield $thing;
};

$third = async () => {
yield $thing;
};

~~~

$first = function (): \Amp\Promise {
return \Amp\call(function () {
yield "here";
Expand Down

0 comments on commit c8b5c8a

Please sign in to comment.