Skip to content

Commit

Permalink
composer updates hook
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrawley committed Jan 15, 2017
1 parent d3f7183 commit 0e3d437
Show file tree
Hide file tree
Showing 7 changed files with 523 additions and 67 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ before_install:
- if [ "${TRAVIS_PHP_VERSION}" == "5.3" ]; then composer remove --no-update --dev satooshi/php-coveralls; fi;
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ]; then echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;
- if [ "${SYMFONY_VERSION:0:3}" == "2.3" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update; fi;
- if [ "${SYMFONY_VERSION:0:3}" == "2.3" ]; then composer remove --dev composer/composer --no-update; fi;
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION}" != "5.3" ]; then composer require --dev league/flysystem:~1.0 --no-update; fi;
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:1}" != "7" ]; then composer require --dev doctrine/mongodb-odm:~1.0 --no-update; yes "" | pecl -q install -f mongo; fi;
- if [ "${SYMFONY_VERSION:-x}" != "x" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
Expand Down
34 changes: 34 additions & 0 deletions Tests/Utils/Composer/BufferedIO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Liip\ImagineBundle\Tests\Utils\Composer;

use Composer\IO\IOInterface;

abstract class BufferedIO implements IOInterface
{
private $buffer = array();

public function write($messages, $newline = true, $verbosity = self::NORMAL)
{
$this->buffer = array_merge($this->buffer, (array) $messages);
}

public function askConfirmation($question, $default = true)
{
$this->buffer[] = $question;
}

public function getBuffer()
{
return $this->buffer;
}
}
149 changes: 149 additions & 0 deletions Tests/Utils/Composer/UpgradeNoticeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Liip\ImagineBundle\Tests\Utils\Composer;

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Package\RootPackageInterface;
use Composer\Script\Event;
use Liip\ImagineBundle\Utils\Composer\UpgradeNotice;

/**
* @covers \Liip\ImagineBundle\Utils\Composer\ConsoleIO
* @covers \Liip\ImagineBundle\Utils\Composer\UpgradeNotice
*/
class UpgradeNoticeTest extends \PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
if (false === version_compare(PHP_VERSION, '5.4', '>=')
|| false === interface_exists('\Composer\IO\IOInterface')) {
static::markTestSkipped('"PHP 5.4" or greater and "\Composer\IO\IOInterface" required to test this component.');
}
}

public function testWrite()
{
$io = $this->getIOMock(true);
$io
->expects($this->atLeastOnce())
->method('write');

UpgradeNotice::doWrite($this->getEventMock($io, '1.7.0'));
UpgradeNotice::doWrite($this->getEventMock($io = $this->getIOMock(), '1.7.0'));

$lineBuffer = $io->getBuffer();
$firstLine = array_shift($lineBuffer);

$this->assertTrue(count($lineBuffer) > 0);
$this->assertContains('Update Notice:', $firstLine);

foreach ($lineBuffer as $b) {
$this->assertContains('liip/imagine-bundle', $b);
}
}

public function testWriteOnUnsupportedVersion()
{
$io = $this->getIOMock(true);
$io
->expects($this->never())
->method('write');

UpgradeNotice::doWrite($this->getEventMock($io, '100.100.100'));
UpgradeNotice::doWrite($this->getEventMock($io = $this->getIOMock(), '100.100.100'));

$this->assertCount(0, $io->getBuffer());
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|IOInterface|BufferedIO
*/
private function getIOMock($mockWrite = false)
{
$io = $this->getMockBuilder('Liip\ImagineBundle\Tests\Utils\Composer\BufferedIO');

if ($mockWrite) {
$io->setMethods(array('write'));
}

return $io->getMockForAbstractClass();
}

/**
* @param IOInterface $io
* @param string $version
*
* @return \PHPUnit_Framework_MockObject_MockObject|Event
*/
private function getEventMock(IOInterface $io, $version)
{
$composer = $this->getComposerMock($this->getPackageMock($version));

$event = $this
->getMockBuilder('Composer\Script\Event')
->setMethods(array('getComposer', 'getIO'))
->disableOriginalConstructor()
->getMock();

$event
->method('getComposer')
->willReturn($composer);

$event
->method('getIO')
->willReturn($io);

return $event;
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|RootPackageInterface
*/
private function getPackageMock($version)
{
$package = $this
->getMockBuilder('Composer\Package\RootPackageInterface')
->setMethods(array('getVersion', 'getName'))
->getMockForAbstractClass();

$package
->method('getVersion')
->willReturn($version);

$package
->method('getName')
->willReturn('liip/imagine-bundle');

return $package;
}

/**
* @param RootPackageInterface $package
*
* @return \PHPUnit_Framework_MockObject_MockObject|Composer
*/
private function getComposerMock(RootPackageInterface $package)
{
$composer = $this
->getMockBuilder('Composer\Composer')
->setMethods(array('getPackage'))
->getMock();

$composer
->method('getPackage')
->willReturn($package);

return $composer;
}
}

0 comments on commit 0e3d437

Please sign in to comment.