-
-
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.
Continued improving tests and testability.
- Loading branch information
Showing
19 changed files
with
411 additions
and
22 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
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,29 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright 2021 Navarr Barnier. All Rights Reserved. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Navarr\Depends\Proxy; | ||
|
||
use JetBrains\PhpStorm\Pure; | ||
use Navarr\Attribute\Dependency; | ||
|
||
class MimeDeterminer | ||
{ | ||
/** | ||
* @return false|string | ||
*/ | ||
#[Pure] | ||
#[Dependency('ext-fileinfo', required: false, reason: 'Usage of mime_content_type if available')] | ||
public function getMimeType(string $path) | ||
{ | ||
if (function_exists('get_mime_type')) { | ||
return mime_content_type($path); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright 2021 Navarr Barnier. All Rights Reserved. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Navarr\Depends\Proxy; | ||
|
||
class StdOutWriter | ||
{ | ||
/** @var false|resource */ | ||
private $resource; | ||
|
||
/** | ||
* @param false|resource $resource | ||
*/ | ||
public function __construct($resource = STDIN) | ||
{ | ||
$this->resource = $resource; | ||
} | ||
|
||
public function canWrite(): bool | ||
{ | ||
return $this->resource !== false; | ||
} | ||
|
||
public function write(string $data): void | ||
{ | ||
if ($this->resource) { | ||
fputs($this->resource, $data); | ||
} | ||
} | ||
|
||
/** | ||
* @param string[] $data | ||
*/ | ||
public function writeCsv(array $data): void | ||
{ | ||
if ($this->resource) { | ||
fputcsv($this->resource, $data); | ||
} | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
/** | ||
* @copyright 2021 Navarr Barnier. All Rights Reserved. | ||
*/ | ||
|
||
namespace Navarr\Depends\Test\Controller\Composer; | ||
|
||
use Composer\Plugin\Capability\CommandProvider; | ||
use Navarr\Depends\Controller\Composer\ComposerCommand; | ||
use Navarr\Depends\Controller\Composer\ComposerPlugin; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ComposerPluginTest extends TestCase | ||
{ | ||
|
||
public function testCommandProviderIsPartOfPlugin() | ||
{ | ||
$plugin = new ComposerPlugin(); | ||
$capabilities = $plugin->getCapabilities(); | ||
$this->assertArrayHasKey(CommandProvider::class, $capabilities); | ||
$this->assertEquals(ComposerPlugin::class, $capabilities[CommandProvider::class]); | ||
} | ||
|
||
public function testContainsOnlyComposerCommands() | ||
{ | ||
$plugin = new ComposerPlugin(); | ||
$commands = $plugin->getCommands(); | ||
|
||
$this->assertIsArray($commands); | ||
$this->assertCount(1, $commands); | ||
$command = end($commands); | ||
$this->assertInstanceOf(ComposerCommand::class, $command); | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright 2021 Navarr Barnier. All Rights Reserved. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Navarr\Depends\Test\Data; | ||
|
||
use Navarr\Depends\Data\DeclaredDependency; | ||
use Navarr\Depends\Data\ReferenceAdder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ReferenceAdderTest extends TestCase | ||
{ | ||
public function testAdd() | ||
{ | ||
$file = uniqid(); | ||
$line = uniqid(); | ||
$package = uniqid(); | ||
$constraint = uniqid(); | ||
$reason = uniqid(); | ||
|
||
$dependency = new DeclaredDependency( | ||
line: $line, | ||
package: $package, | ||
constraint: $constraint, | ||
reason: $reason | ||
); | ||
|
||
$this->assertEquals($package, $dependency->getPackage()); | ||
$this->assertEquals($constraint, $dependency->getConstraint()); | ||
$this->assertEquals($reason, $dependency->getReason()); | ||
$this->assertEquals($line, $dependency->getLine()); | ||
$this->assertNull($dependency->getFile()); | ||
$this->assertNull($dependency->getReference()); | ||
|
||
$referenceAdder = new ReferenceAdder(); | ||
$dependency2 = $referenceAdder->add( | ||
$dependency, | ||
$file | ||
); | ||
|
||
// Ensure original hasn't changed | ||
$this->assertEquals($package, $dependency->getPackage()); | ||
$this->assertEquals($constraint, $dependency->getConstraint()); | ||
$this->assertEquals($reason, $dependency->getReason()); | ||
$this->assertEquals($line, $dependency->getLine()); | ||
$this->assertNull($dependency->getFile()); | ||
$this->assertNull($dependency->getReference()); | ||
|
||
// Check new | ||
$this->assertEquals($package, $dependency2->getPackage()); | ||
$this->assertEquals($constraint, $dependency2->getConstraint()); | ||
$this->assertEquals($reason, $dependency2->getReason()); | ||
$this->assertEquals($line, $dependency2->getLine()); | ||
$this->assertEquals($file, $dependency2->getFile()); | ||
$this->assertEquals("{$file}:{$line}", $dependency2->getReference()); | ||
} | ||
} |
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
Oops, something went wrong.