-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to run command with a boot file
- Loading branch information
1 parent
3aec0eb
commit 2e5cc16
Showing
12 changed files
with
318 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml export-ignore | ||
/tests export-ignore | ||
|
||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
composer.phar | ||
composer.lock | ||
/coverage/ | ||
/vendor/ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
forceCoversAnnotation="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src/Carbon</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<testsuites> | ||
<testsuite name="carbon"> | ||
<directory suffix="Test.php">tests/Carbon</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Carbon\Tests; | ||
|
||
use Carbon\Cli; | ||
use Carbon\Command\Macro; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Carbon\Cli | ||
*/ | ||
class CliTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::getCommands | ||
*/ | ||
public function testGetCommands() | ||
{ | ||
$this->assertSame([ | ||
'macro' => Macro::class, | ||
], (new Cli())->getCommands()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Carbon\Tests\Command; | ||
|
||
use Carbon\Cli; | ||
use Carbon\Tests\DummyMixin; | ||
use Carbon\Tests\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Carbon\Command\Macro | ||
*/ | ||
class MacroTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::run | ||
* @covers \Carbon\Types\Generator::getMethods | ||
* @covers \Carbon\Types\Generator::getMethodsDefinitions | ||
* @covers \Carbon\Types\Generator::dumpParameter | ||
* @covers \Carbon\Types\Generator::dumpValue | ||
* @covers \Carbon\Types\Generator::writeHelpers | ||
*/ | ||
public function testRun() | ||
{ | ||
$dir = sys_get_temp_dir().'/macro-test-'.mt_rand(0, 999999); | ||
@mkdir($dir); | ||
chdir($dir); | ||
$cli = new Cli(); | ||
$cli->mute(); | ||
$cli('carbon', 'macro', DummyMixin::class, '--source-path', __DIR__.'/..'); | ||
|
||
$this->assertSame([ | ||
'.', | ||
'..', | ||
'types', | ||
], scandir($dir)); | ||
$this->assertSame([ | ||
'.', | ||
'..', | ||
'_ide_carbon_mixin_instantiated.php', | ||
'_ide_carbon_mixin_static.php', | ||
], scandir("$dir/types")); | ||
$this->assertFileEquals(__DIR__.'/_ide_carbon_mixin_instantiated.php', "$dir/types/_ide_carbon_mixin_instantiated.php"); | ||
$this->assertFileEquals(__DIR__.'/_ide_carbon_mixin_static.php', "$dir/types/_ide_carbon_mixin_static.php"); | ||
|
||
$this->removeDirectory($dir); | ||
} | ||
|
||
/** | ||
* @covers ::run | ||
* @covers \Carbon\Types\Generator::getMethods | ||
* @covers \Carbon\Types\Generator::getMethodsDefinitions | ||
* @covers \Carbon\Types\Generator::dumpParameter | ||
* @covers \Carbon\Types\Generator::dumpValue | ||
* @covers \Carbon\Types\Generator::writeHelpers | ||
*/ | ||
public function testRunWithFile() | ||
{ | ||
$dir = sys_get_temp_dir().'/macro-test-'.mt_rand(0, 999999); | ||
@mkdir($dir); | ||
chdir($dir); | ||
file_put_contents('test.php', '<?php \Carbon\Carbon::macro(\'foo\', function () { return 42; });'); | ||
$cli = new Cli(); | ||
$cli->mute(); | ||
$cli('carbon', 'macro', 'test.php'); | ||
|
||
$contents = file_get_contents("$dir/types/_ide_carbon_mixin_instantiated.php"); | ||
$this->assertStringContainsString('public function foo()', $contents); | ||
|
||
$this->removeDirectory($dir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Carbon | ||
{ | ||
class Carbon | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} | ||
|
||
namespace Carbon | ||
{ | ||
class CarbonImmutable | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} | ||
|
||
namespace Illuminate\Support | ||
{ | ||
class Carbon | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} | ||
|
||
namespace Illuminate\Support\Facades | ||
{ | ||
class Date | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Carbon | ||
{ | ||
class Carbon | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public static function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} | ||
|
||
namespace Carbon | ||
{ | ||
class CarbonImmutable | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public static function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} | ||
|
||
namespace Illuminate\Support | ||
{ | ||
class Carbon | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public static function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} | ||
|
||
namespace Illuminate\Support\Facades | ||
{ | ||
class Date | ||
{ | ||
/** | ||
* @see \DummyMixin::sayHi | ||
* | ||
* Say "Hi!" to a given person name. | ||
*/ | ||
public static function sayHi(string $name) | ||
{ | ||
// Content, see src/DummyMixin.php:15 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?php | ||
|
||
namespace Carbon; | ||
namespace Carbon\Tests; | ||
|
||
class Test | ||
class DummyMixin | ||
{ | ||
/** | ||
* @return \Closure | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Carbon\Tests; | ||
|
||
use PHPUnit\Framework\TestCase as FrameworkTestCase; | ||
|
||
class TestCase extends FrameworkTestCase | ||
{ | ||
/** | ||
* Remove a directory and all sub-directories and files inside. | ||
* | ||
* @param string $directory | ||
* | ||
* @return void | ||
*/ | ||
protected function removeDirectory($directory) | ||
{ | ||
if (!($dir = @opendir($directory))) { | ||
return; | ||
} | ||
|
||
while (false !== ($file = readdir($dir))) { | ||
if ($file === '.' || $file === '..') { | ||
continue; | ||
} | ||
|
||
if (is_dir($directory.'/'.$file)) { | ||
$this->removeDirectory($directory.'/'.$file); | ||
|
||
continue; | ||
} | ||
|
||
unlink($directory.'/'.$file); | ||
} | ||
|
||
closedir($dir); | ||
|
||
@rmdir($directory); | ||
} | ||
} |