-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
137 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
vendor | ||
composer.lock | ||
.php_cs.cache | ||
.phpunit.result.cache | ||
.*.sw? |
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,8 @@ | ||
version: "3" | ||
|
||
services: | ||
phpunit: | ||
image: hillliu/pmvc-phpunit:5.6 | ||
volumes: | ||
- .:/var/www/html | ||
- .:/var/www/supervisor |
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 | ||
$path = __DIR__.'/vendor/autoload.php'; | ||
require $path; | ||
\PMVC\Load::plug(); | ||
\PMVC\addPlugInFolders(['../']); | ||
|
||
if (!class_exists('PHPUnit_Framework_TestCase')) { | ||
class PHPUnit_Framework_TestCase extends | ||
\PHPUnit\Framework\TestCase | ||
{ | ||
} | ||
} | ||
|
||
class PMVC_TestCase extends PHPUnit_Framework_TestCase | ||
{ | ||
public function haveString($needle, $haystack) { | ||
if (is_callable([$this, "assertStringContainsString"])) { | ||
$this->assertStringContainsString($needle, $haystack); | ||
} else { | ||
$this->assertContains($needle, $haystack); | ||
} | ||
} | ||
} |
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,12 @@ | ||
#!/bin/bash | ||
|
||
DIR="$( cd "$(dirname "$0")" ; pwd -P )" | ||
PLUGIN_NAME="supervisor" | ||
|
||
docker run --rm \ | ||
-v $DIR:/var/www/html \ | ||
-v $DIR:/var/www/${PLUGIN_NAME} \ | ||
--name phpunit hillliu/pmvc-phpunit:5.6 \ | ||
phpunit --no-configuration --bootstrap ./include_test.php ./tests-legacy/ | ||
|
||
# docker-compose run --rm phpunit phpunit --no-configuration --bootstrap ./include_test.php ./tests-legacy/test.php |
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
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,84 @@ | ||
<?php | ||
|
||
use PMVC_TestCase; | ||
|
||
class SupervisorTest extends PMVC_TestCase | ||
{ | ||
private $_plug = 'supervisor'; | ||
|
||
protected function teardown(): void | ||
{ | ||
\PMVC\unplug($this->_plug); | ||
} | ||
|
||
function testPlugin() | ||
{ | ||
ob_start(); | ||
print_r(PMVC\plug($this->_plug)); | ||
$output = ob_get_contents(); | ||
ob_end_clean(); | ||
$this->haveString($this->_plug,$output); | ||
} | ||
|
||
function testScript() | ||
{ | ||
$plug = PMVC\plug($this->_plug); | ||
$s = 'helloScript'; | ||
@$plug->script(new fakeChild(), array($s, 0)); | ||
$self = $this; | ||
@$plug->process(function() use($plug, $self, $s){ | ||
$plug->stop(); | ||
$self->assertEquals($s,$plug['callbacks'][0]['args'][0]); | ||
}); | ||
} | ||
|
||
function testDaemon() | ||
{ | ||
$s = 'helloDaemon'; | ||
$plug = PMVC\plug($this->_plug); | ||
@$plug->daemon(new fakeDaemon(), [$s, 1]); | ||
@$plug->process(function() use ($plug) { | ||
$plug->forceStop(); | ||
$this->assertEquals('daemon',$plug['callbacks'][0]['type']); | ||
}); | ||
} | ||
|
||
function testTrigger() | ||
{ | ||
$plug = PMVC\plug($this->_plug); | ||
$s = 'helloTrigger'; | ||
$self = $this; | ||
@$childKey = $plug->script(new fakeChild(), array($s.'3', 3)); | ||
@$second = $plug->script(new fakeChild(), array($s.'4', 4), $childKey); | ||
@$third = $plug->script(new fakeChild(), array($s.'5', 5), $second); | ||
@$plug->process(function($callbackId, $pid) use($plug, $self, $second){ | ||
static $i = 0; | ||
if (!$i) { | ||
$self->assertTrue(empty($plug['callbacks'][$second]['startTime']), 'Test first'); | ||
} else { | ||
$self->assertFalse(empty($plug['callbacks'][$second]['startTime']), 'Test second'); | ||
} | ||
$i++; | ||
}); | ||
} | ||
} | ||
|
||
class fakeChild | ||
{ | ||
function __invoke($s, $exit) | ||
{ | ||
echo $s."\n"; | ||
exit($exit); | ||
} | ||
} | ||
|
||
/** | ||
* fakeDaemon without exit | ||
*/ | ||
class fakeDaemon | ||
{ | ||
function __invoke($s, $exit) | ||
{ | ||
echo $s."\n"; | ||
} | ||
} |