Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ComposerFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class ComposerFactoryTest extends \PHPUnit\Framework\TestCase
15 {
17  private $testComposerHome = __DIR__ . '/_files/composer_home';
18 
20  private $fixturesDir = __DIR__ . '/_files/';
21 
23  private $originalComposerHome;
24 
26  private $fileDriver;
27 
28  public function setUp()
29  {
30  $this->fileDriver = new File();
31  $this->originalComposerHome = getenv('COMPOSER_HOME');
32  putenv('COMPOSER_HOME');
33  }
34 
35  public function tearDown()
36  {
37  if ($this->originalComposerHome) {
38  putenv('COMPOSER_HOME=' . $this->originalComposerHome);
39  }
40 
41  // Composer home directory is created one level up from where composer.json is.
42  if (is_dir($this->testComposerHome)) {
43  $this->fileDriver->deleteDirectory($this->testComposerHome);
44  }
45  }
46 
47  public function testCreate()
48  {
49  $objectManager = new ObjectManager($this);
50  $dirListMock = $this->getMockBuilder(DirectoryList::class)->disableOriginalConstructor()->getMock();
51  $composerJsonFinderMock = $this->getMockBuilder(ComposerJsonFinder::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54 
55  $composerJsonPath = $this->fixturesDir . 'composer.json';
56 
57  $dirListMock->expects($this->once())
58  ->method('getPath')
59  ->willReturn($this->testComposerHome);
60  $composerJsonFinderMock->expects($this->once())
61  ->method('findComposerJson')
62  ->willReturn($composerJsonPath);
63 
65  $factory = $objectManager->getObject(
66  ComposerFactory::class,
67  [
68  'directoryList' => $dirListMock,
69  'composerJsonFinder' => $composerJsonFinderMock
70  ]
71  );
72 
73  $this->assertInstanceOf(\Composer\Composer::class, $factory->create());
74  }
75 }
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60