File: FactoryTest.php

package info (click to toggle)
composer 2.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,528 kB
  • sloc: php: 83,030; makefile: 59; xml: 39
file content (66 lines) | stat: -rw-r--r-- 1,895 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php declare(strict_types=1);

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Test;

use Composer\Factory;
use Composer\Util\Platform;

class FactoryTest extends TestCase
{
    public function tearDown(): void
    {
        parent::tearDown();
        Platform::clearEnv('COMPOSER');
    }

    /**
     * @group TLS
     */
    public function testDefaultValuesAreAsExpected(): void
    {
        $ioMock = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();

        $ioMock->expects($this->once())
            ->method("writeError")
            ->with($this->equalTo('<warning>You are running Composer with SSL/TLS protection disabled.</warning>'));

        $config = $this
            ->getMockBuilder('Composer\Config')
            ->getMock();

        $config->method('get')
            ->with($this->equalTo('disable-tls'))
            ->willReturn(true);

        Factory::createHttpDownloader($ioMock, $config);
    }

    public function testGetComposerJsonPath(): void
    {
        self::assertSame('./composer.json', Factory::getComposerFile());
    }

    public function testGetComposerJsonPathFailsIfDir(): void
    {
        Platform::putEnv('COMPOSER', __DIR__);
        self::expectException('RuntimeException');
        self::expectExceptionMessage('The COMPOSER environment variable is set to '.__DIR__.' which is a directory, this variable should point to a composer.json or be left unset.');
        Factory::getComposerFile();
    }

    public function testGetComposerJsonPathFromEnv(): void
    {
        Platform::putEnv('COMPOSER', ' foo.json ');
        self::assertSame('foo.json', Factory::getComposerFile());
    }
}