Source of file CheckComposerUpdatesExtensionTest.php
Size: 2,760 Bytes - Last Modified: 2021-12-23T10:37:59+00:00
/var/www/docs.ssmods.com/process/src/tests/Extensions/CheckComposerUpdatesExtensionTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | <?php namespace BringYourOwnIdeas\UpdateChecker\Tests\Extensions; use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask; use BringYourOwnIdeas\UpdateChecker\Extensions\CheckComposerUpdatesExtension; use BringYourOwnIdeas\UpdateChecker\Extensions\ComposerLoaderExtension; use BringYourOwnIdeas\UpdateChecker\Tests\Stubs\ComposerLoaderExtensionStub; use BringYourOwnIdeas\UpdateChecker\UpdateChecker; use Composer\Package\PackageInterface; use PHPUnit_Framework_TestCase; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; /** * @mixin PHPUnit_Framework_TestCase */ class CheckComposerUpdatesExtensionTest extends SapphireTest { protected $usesDatabase = true; /** * @var UpdatePackageInfoTask|CheckComposerUpdatesExtension */ protected $task; /** * @var string[] */ protected $allowedTypes; protected function setUp(): void { parent::setUp(); // Register the extension stub for unit testing to avoid loading Composer Config::modify()->merge(Injector::class, ComposerLoaderExtension::class, [ 'class' => ComposerLoaderExtensionStub::class, ]); // Create the task for testing $this->task = UpdatePackageInfoTask::create(); // Create a partial mock of the update checker $updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->setMethods(['checkForUpdates'])->getMock(); $this->task->setUpdateChecker($updateCheckerMock); $this->allowedTypes = ['silverstripe-module', 'silverstripe-vendormodule', 'silverstripe-theme']; Config::modify()->set(UpdatePackageInfoTask::class, 'allowed_types', $this->allowedTypes); } public function testRunPassesPackagesToUpdateChecker() { $this->task->getUpdateChecker()->expects($this->atLeastOnce()) ->method('checkForUpdates') ->with($this->isInstanceOf(PackageInterface::class), $this->isType('string')) ->will($this->returnValue([])); $this->runTask(); } public function testOnlyAllowedPackageTypesAreProcessed() { $this->task->getUpdateChecker()->expects($this->atLeastOnce()) ->method('checkForUpdates') ->with($this->callback(function ($argument) { return in_array($argument->getType(), $this->allowedTypes); })) ->will($this->returnValue([])); $this->runTask(); } /** * Runs the task and buffers the output (tasks output directly) * * @return string Task output */ protected function runTask() { ob_start(); $this->task->run(null); return ob_get_clean(); } } |