Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F24927909
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Build/TriggerBuildFactory.php b/src/Build/TriggerBuildFactory.php
index 34b68af..d04614f 100644
--- a/src/Build/TriggerBuildFactory.php
+++ b/src/Build/TriggerBuildFactory.php
@@ -1,85 +1,92 @@
<?php
namespace Keruald\DockerHub\Build;
use Keruald\DockerHub\DockerHubImage;
use GuzzleHttp\ClientInterface;
use InvalidArgumentException;
/**
* Allows to build several TriggerBuild instances
* with the same HTTP client and a collection of tokens.
*/
class TriggerBuildFactory {
///
/// Private members, to pass to instances
///
/**
* @var $array
*/
private $tokens;
/**
* @var \GuzzleHttp\ClientInterface
*/
private $client;
///
/// Constructor
///
/**
* Initializes a new instance of the TriggerBuildFactory object.
*
* @param \GuzzleHttp\ClientInterface $client HTTP client
* @param array $tokens The tokens for the image
*/
public function __construct (ClientInterface $client, array $tokens) {
$this->client = $client;
$this->tokens = $tokens;
}
///
/// Builder
///
/**
* Builds a new TriggerBuild instance for the specified image.
*
* @param string $image The image name
* @return TriggerBuild
*/
public function getForImage ($image) {
return new TriggerBuild(
DockerHubImage::loadFromSlashNotation($image),
$this->getToken($image),
$this->client
);
}
/**
* Sends to registry a payload to trigger a build for the specified image.
*
* @param string $image The image name
*/
public function build ($image) {
$this->getForImage($image)->sendPayloadForAll();
}
+ /**
+ * @return bool
+ */
+ public function hasToken ($image) {
+ return array_key_exists($image, $this->tokens);
+ }
+
///
/// Helper methods
///
protected function getToken ($image) {
- if (array_key_exists($image, $this->tokens)) {
+ if ($this->hasToken($image)) {
return $this->tokens[$image];
}
throw new InvalidArgumentException("No token found for image $image.");
}
}
diff --git a/tests/Build/TriggerBuildFactoryTest.php b/tests/Build/TriggerBuildFactoryTest.php
index 3d3b17d..77c2cf1 100644
--- a/tests/Build/TriggerBuildFactoryTest.php
+++ b/tests/Build/TriggerBuildFactoryTest.php
@@ -1,56 +1,64 @@
<?php
namespace Keruald\DockerHub\Tests\Build;
use Keruald\DockerHub\DockerHubImage;
use Keruald\DockerHub\Build\TriggerBuild;
use Keruald\DockerHub\Build\TriggerBuildFactory;
use Keruald\DockerHub\Tests\WithMockHttpClient;
class TriggerBuildFactoryTest extends \PHPUnit_Framework_TestCase {
use WithMockHttpClient;
/**
* @var Keruald\DockerHub\Build\TriggerBuildFactory
*/
protected $factory;
public function setUp () {
$client = self::mockHttpClient();
$tokens = self::mockTokens();
$this->factory = new TriggerBuildFactory($client, $tokens);
}
/**
* @return array
*/
private static function mockTokens () {
return [
"acme/foo" => "0000",
];
}
public function testGetForImage () {
$this->assertInstanceOf(
TriggerBuild::class,
$this->factory->getForImage("acme/foo")
);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testGetForImageWithoutToken () {
$this->factory->getForImage("acme/bar");
}
public function testBuild () {
// That returns void.
// We don't need to test the sendPayloadForAll method.
// So, we only need to check there is no exception or error.
$this->factory->build("acme/foo");
}
+ public function testHasToken () {
+ $this->assertTrue($this->factory->hasToken("acme/foo"));
+ }
+
+ public function testHasTokenWhenWeDoNot () {
+ $this->assertFalse($this->factory->hasToken("acme/bar"));
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Mar 21, 04:44 (12 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3546425
Default Alt Text
(4 KB)
Attached To
Mode
rKDOCKERHUB Keruald Docker Hub
Attached
Detach File
Event Timeline
Log In to Comment