1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Get rid of prophecy usage

This commit is contained in:
Jordi Boggiano 2021-12-10 12:57:08 +01:00
parent ed08c40ab5
commit 22fed0d445
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
6 changed files with 88 additions and 692 deletions

View file

@ -14,84 +14,112 @@ namespace Composer\Test\Package;
use Composer\Package\Link;
use Composer\Package\RootAliasPackage;
use Composer\Package\RootPackage;
use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Test\TestCase;
use Prophecy\Argument;
use PHPUnit\Framework\MockObject\MockObject;
class RootAliasPackageTest extends TestCase
{
public function testUpdateRequires()
{
$root = $this->getMockRootPackageInterface();
$root->setRequires(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getRequires());
$links = array(new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_REQUIRE, 'self.version'));
$root = $this->getMockRootPackage();
$root->expects($this->once())
->method('setRequires')
->with($this->equalTo($links));
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
$this->assertEmpty($alias->getRequires());
$alias->setRequires($links);
$this->assertNotEmpty($alias->getRequires());
}
public function testUpdateDevRequires()
{
$root = $this->getMockRootPackageInterface();
$root->setDevRequires(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getDevRequires());
$links = array(new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_DEV_REQUIRE, 'self.version'));
$root = $this->getMockRootPackage();
$root->expects($this->once())
->method('setDevRequires')
->with($this->equalTo($links));
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
$this->assertEmpty($alias->getDevRequires());
$alias->setDevRequires($links);
$this->assertNotEmpty($alias->getDevRequires());
}
public function testUpdateConflicts()
{
$root = $this->getMockRootPackageInterface();
$root->setConflicts(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getConflicts());
$links = array(new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_CONFLICT, 'self.version'));
$root = $this->getMockRootPackage();
$root->expects($this->once())
->method('setConflicts')
->with($this->equalTo($links));
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
$this->assertEmpty($alias->getConflicts());
$alias->setConflicts($links);
$this->assertNotEmpty($alias->getConflicts());
}
public function testUpdateProvides()
{
$root = $this->getMockRootPackageInterface();
$root->setProvides(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getProvides());
$links = array(new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_PROVIDE, 'self.version'));
$root = $this->getMockRootPackage();
$root->expects($this->once())
->method('setProvides')
->with($this->equalTo($links));
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
$this->assertEmpty($alias->getProvides());
$alias->setProvides($links);
$this->assertNotEmpty($alias->getProvides());
}
public function testUpdateReplaces()
{
$root = $this->getMockRootPackageInterface();
$root->setReplaces(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getReplaces());
$links = array(new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_REPLACE, 'self.version'));
$root = $this->getMockRootPackage();
$root->expects($this->once())
->method('setReplaces')
->with($this->equalTo($links));
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
$this->assertEmpty($alias->getReplaces());
$alias->setReplaces($links);
$this->assertNotEmpty($alias->getReplaces());
}
/**
* @return \Prophecy\Prophecy\ObjectProphecy
* @return RootPackage&MockObject
*/
protected function getMockRootPackageInterface()
protected function getMockRootPackage()
{
$root = $this->prophesize('Composer\\Package\\RootPackage');
$root->getName()->willReturn('something/something')->shouldBeCalled();
$root->getRequires()->willReturn(array())->shouldBeCalled();
$root->getDevRequires()->willReturn(array())->shouldBeCalled();
$root->getConflicts()->willReturn(array())->shouldBeCalled();
$root->getProvides()->willReturn(array())->shouldBeCalled();
$root->getReplaces()->willReturn(array())->shouldBeCalled();
$root = $this->getMockBuilder(RootPackage::class)->disableOriginalConstructor()->getMock();
$root->expects($this->atLeastOnce())
->method('getName')
->willReturn('something/something');
$root->expects($this->atLeastOnce())
->method('getRequires')
->willReturn(array());
$root->expects($this->atLeastOnce())
->method('getDevRequires')
->willReturn(array());
$root->expects($this->atLeastOnce())
->method('getConflicts')
->willReturn(array());
$root->expects($this->atLeastOnce())
->method('getProvides')
->willReturn(array());
$root->expects($this->atLeastOnce())
->method('getReplaces')
->willReturn(array());
return $root;
}