-
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
4 changed files
with
103 additions
and
4 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
Empty file.
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,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\helfi_drupal_tools\Kernel; | ||
|
||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\Tests\helfi_api_base\Traits\ApiTestTrait; | ||
use DrupalTools\Drush\Commands\CheckPackageVersionsCommands; | ||
use Drush\Commands\DrushCommands; | ||
use GuzzleHttp\Psr7\Response; | ||
use Prophecy\Argument; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
/** | ||
* Tests Package version checker commands. | ||
* | ||
* @group helfi_drupal_tools | ||
*/ | ||
final class CheckPackageVersionsCommandsTest extends KernelTestBase { | ||
|
||
use ApiTestTrait; | ||
use ProphecyTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = ['helfi_api_base']; | ||
|
||
/** | ||
* Tests version check with invalid composer.json file. | ||
*/ | ||
public function testInvalidComposerFile() : void { | ||
$this->expectException(\RuntimeException::class); | ||
CheckPackageVersionsCommands::create($this->container)->checkVersions('nonexistent.lock'); | ||
} | ||
|
||
/** | ||
* Tests version check. | ||
*/ | ||
public function testVersionCheck() : void { | ||
$this->setupMockHttpClient([ | ||
new Response(body: json_encode([ | ||
'packages' => [ | ||
'drupal/helfi_api_base' => [ | ||
[ | ||
'name' => 'drupal/helfi_api_base', | ||
'version' => '1.1.0', | ||
], | ||
], | ||
], | ||
])), | ||
new Response(body: json_encode([ | ||
'packages' => [ | ||
'drupal/helfi_api_base' => [ | ||
[ | ||
'name' => 'drupal/helfi_api_base', | ||
'version' => '1.0.18', | ||
], | ||
], | ||
], | ||
])), | ||
]); | ||
$io = $this->prophesize(StyleInterface::class); | ||
$io->table(Argument::any(), [ | ||
[ | ||
'name' => 'drupal/helfi_api_base', | ||
'currentVersion' => '1.0.18', | ||
'latestVersion' => '1.1.0', | ||
], | ||
])->shouldBeCalledTimes(1); | ||
|
||
$sut = new CheckPackageVersionsCommands( | ||
$this->container->get('helfi_api_base.package_version_checker'), | ||
$io->reveal(), | ||
); | ||
// Test with old version and make sure we exit with failure. | ||
$return = $sut->checkVersions(__DIR__ . '/../../fixtures/composer.lock'); | ||
$this->assertEquals(DrushCommands::EXIT_FAILURE_WITH_CLARITY, $return); | ||
|
||
// Test with up-to-date version and make sure we exit with success. | ||
$return = $sut->checkVersions(__DIR__ . '/../../fixtures/composer.lock'); | ||
$this->assertEquals(DrushCommands::EXIT_SUCCESS, $return); | ||
} | ||
|
||
} |