Fixed PHPUnit for phar.

This commit is contained in:
李铭昕 2020-11-26 18:00:16 +08:00
parent 7d7a797ab4
commit e5164a5298
10 changed files with 56 additions and 65 deletions

View File

@ -46,3 +46,4 @@ parameters:
- '#Function getSwooleTracker.* not found#'
- '#Call to an undefined method Hyperf\\Database\\Model\\Builder::unsearchable#'
- '#trackerHookMalloc not found#'
- '#method Phar\:\:buildFromIterator\(\) expects Iterator, Traversable given#'

View File

@ -40,6 +40,7 @@
<directory suffix="Test.php">./src/metric/tests</directory>
<directory suffix="Test.php">./src/model-cache/tests</directory>
<directory suffix="Test.php">./src/paginator/tests</directory>
<directory suffix="Test.php">./src/phar/tests</directory>
<directory suffix="Test.php">./src/pool/tests</directory>
<directory suffix="Test.php">./src/process/tests</directory>
<directory suffix="Test.php">./src/protocol/tests</directory>
@ -92,6 +93,7 @@
<directory suffix=".php">./src/model-cache/src</directory>
<directory suffix=".php">./src/nsq/src</directory>
<directory suffix=".php">./src/paginator/src</directory>
<directory suffix=".php">./src/phar/src</directory>
<directory suffix=".php">./src/redis/src</directory>
<directory suffix=".php">./src/rpc/src</directory>
<directory suffix=".php">./src/server/src</directory>

View File

@ -36,7 +36,7 @@ class BuildCommand extends HyperfCommand
}
/**
* tips
* tips.
*/
public function configure()
{
@ -80,7 +80,6 @@ class BuildCommand extends HyperfCommand
/**
* @param $path
* @param string|null $version
* @return HyperfPhar
*/
public function getPhar($path, ?string $version = null)

View File

@ -27,7 +27,6 @@ class Bundle implements IteratorAggregate
/**
* Add a file to the resource bundle.
* @param string $file
* @return Bundle
*/
public function addFile(string $file)
@ -38,7 +37,6 @@ class Bundle implements IteratorAggregate
/**
* Add a directory package to a resource package.
* @param Finder $dir
* @return Bundle
*/
public function addDir(Finder $dir)
@ -49,7 +47,6 @@ class Bundle implements IteratorAggregate
/**
* Determines whether the file exists in the resource bundle.
* @param string $resource
* @return bool
*/
public function checkContains(string $resource)
@ -65,10 +62,17 @@ class Bundle implements IteratorAggregate
return false;
}
/**
* Returns an iterator for a list of resources.
* @return ArrayIterator|Traversable
*/
public function getIterator()
{
return new ArrayIterator($this->resource_list);
}
/**
* Determines whether the file exists in the folder resource bundle.
* @param Finder $dir
* @param string $resource
* @return bool
*/
private function directoryContains(Finder $dir, string $resource)
@ -82,15 +86,4 @@ class Bundle implements IteratorAggregate
return false;
}
/**
* Returns an iterator for a list of resources.
* @return ArrayIterator|Traversable
*/
public function getIterator()
{
return new ArrayIterator($this->resource_list);
}
}

View File

@ -49,8 +49,6 @@ class HyperfPhar
/**
* HyperfPhar constructor.
* @param ContainerInterface $container
* @param string $path
*/
public function __construct(ContainerInterface $container, string $path)
{
@ -61,7 +59,7 @@ class HyperfPhar
/**
* Gets the Phar package name.
* @return TargetPhar|string
* @return string|TargetPhar
*/
public function getTarget()
{
@ -88,7 +86,6 @@ class HyperfPhar
/**
* Gets the default run script path.
* @return string
*/
public function getMain(): string
{
@ -160,30 +157,6 @@ class HyperfPhar
return $packages;
}
/**
* Load the configuration.
* @param $path
* @return mixed
*/
private function loadJson($path)
{
$ret = json_decode(file_get_contents($path), true);
if ($ret === null) {
throw new InvalidArgumentException('Unable to parse given path "' . $path . '"', json_last_error());
}
return $ret;
}
/**
* Get file size.
* @param $path
* @return string
*/
private function getSize($path)
{
return round(filesize($path) / 1024, 1) . ' KiB';
}
/**
* Gets the relative path relative to the resource bundle.
* @param $path
@ -267,4 +240,28 @@ class HyperfPhar
$this->log('');
$this->log(' <info>OK</info> - Creating <info>' . $this->getTarget() . '</info> (' . $this->getSize($this->getTarget()) . ') completed after ' . round($time, 1) . 's');
}
}
/**
* Load the configuration.
* @param $path
* @return mixed
*/
private function loadJson($path)
{
$ret = json_decode(file_get_contents($path), true);
if ($ret === null) {
throw new InvalidArgumentException('Unable to parse given path "' . $path . '"', json_last_error());
}
return $ret;
}
/**
* Get file size.
* @param $path
* @return string
*/
private function getSize($path)
{
return round(filesize($path) / 1024, 1) . ' KiB';
}
}

View File

@ -21,7 +21,6 @@ class Package
/**
* Package constructor.
* @param array $package
* @param $directory
*/
public function __construct(array $package, $directory)
@ -31,8 +30,8 @@ class Package
}
/**
* Get full package name
* @return mixed|null
* Get full package name.
* @return null|mixed
*/
public function getName()
{
@ -85,7 +84,6 @@ class Package
public function bundle()
{
$bundle = new Bundle();
if (empty($this->package['autoload']) && ! is_dir($this->directory . $this->getPathVendor())) {
return $bundle;
}

View File

@ -44,7 +44,6 @@ class TargetPhar
/**
* Add a resource bundle to the Phar package.
* @param Bundle $bundle
*/
public function addBundle(Bundle $bundle)
{
@ -69,7 +68,6 @@ class TargetPhar
/**
* Add folder resources to the Phar package.
* @param Traversable $iterator
*/
public function buildFromIterator(Traversable $iterator)
{
@ -78,8 +76,6 @@ class TargetPhar
/**
* Create the default execution file.
* @param string|null $indexFile
* @param string|null $webIndexFile
* @return string
*/
public function createDefaultStub(string $indexFile = null, string $webIndexFile = null)
@ -89,7 +85,6 @@ class TargetPhar
/**
* Set the default startup file.
* @param string $stub
*/
public function setStub(string $stub)
{

View File

@ -20,9 +20,6 @@ use PHPUnit\Framework\TestCase;
*/
class PackageTest extends TestCase
{
/**
* 测试默认值
*/
public function testDefaults()
{
$package = new Package([], 'dirs/');
@ -34,9 +31,6 @@ class PackageTest extends TestCase
$this->assertEquals('vendor/', $package->getPathVendor());
}
/**
* 测试自定义数据.
*/
public function testPackage()
{
$package = new Package([
@ -55,7 +49,11 @@ class PackageTest extends TestCase
public function testBundleWillContainComposerJsonButNotVendor()
{
$dir = realpath(__DIR__ . '/fixtures/03-project-with-phars') . '/';
$package = new Package([], $dir);
$package = new Package([
'config' => [
'vendor-dir' => 'vendors',
],
], $dir);
$bundle = $package->bundle();
$this->assertTrue($bundle->checkContains($dir . 'composer.json'));
@ -67,7 +65,11 @@ class PackageTest extends TestCase
public function testBundleWillNotContainComposerPharInRoot()
{
$dir = realpath(__DIR__ . '/fixtures/03-project-with-phars') . '/';
$package = new Package([], $dir);
$package = new Package([
'config' => [
'vendor-dir' => 'vendors',
],
], $dir);
$bundle = $package->bundle();
$this->assertFalse($bundle->checkContains($dir . 'composer.phar'));
@ -77,7 +79,11 @@ class PackageTest extends TestCase
public function testBundleWillContainComposerPharFromSrc()
{
$dir = realpath(__DIR__ . '/fixtures/04-project-with-phars-in-src') . '/';
$package = new Package([], $dir);
$package = new Package([
'config' => [
'vendor-dir' => 'vendors',
],
], $dir);
$bundle = $package->bundle();
$this->assertTrue($bundle->checkContains($dir . 'composer.json'));