2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2014-10-21 08:25:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Repository\Vcs;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2021-12-09 21:14:04 +00:00
|
|
|
use Composer\Json\JsonFile;
|
2014-10-21 08:25:24 +00:00
|
|
|
use Composer\Repository\Vcs\GitLabDriver;
|
|
|
|
use Composer\Config;
|
2021-12-09 16:09:07 +00:00
|
|
|
use Composer\Test\Mock\HttpDownloaderMock;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2016-01-21 12:01:55 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2021-12-09 16:09:07 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-10-31 11:44:54 +00:00
|
|
|
use Composer\Util\Http\Response;
|
2014-10-21 08:25:24 +00:00
|
|
|
|
2015-02-20 22:12:48 +00:00
|
|
|
/**
|
|
|
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
class GitLabDriverTest extends TestCase
|
2014-10-21 08:25:24 +00:00
|
|
|
{
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
private $home;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
private $config;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
2021-12-09 16:09:07 +00:00
|
|
|
* @var MockObject&IOInterface
|
2021-10-16 08:16:06 +00:00
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
private $io;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
2021-12-09 16:09:07 +00:00
|
|
|
* @var MockObject&ProcessExecutor
|
2021-10-16 08:16:06 +00:00
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
private $process;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
2021-12-09 16:09:07 +00:00
|
|
|
* @var HttpDownloaderMock
|
2021-10-16 08:16:06 +00:00
|
|
|
*/
|
2018-10-31 11:44:54 +00:00
|
|
|
private $httpDownloader;
|
2016-01-21 12:01:55 +00:00
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2014-10-21 08:25:24 +00:00
|
|
|
{
|
2022-05-11 14:05:35 +00:00
|
|
|
$this->home = self::getUniqueTmpDirectory();
|
2022-02-23 15:57:47 +00:00
|
|
|
$this->config = $this->getConfig([
|
|
|
|
'home' => $this->home,
|
2022-08-17 12:20:07 +00:00
|
|
|
'gitlab-domains' => [
|
2022-02-23 15:57:47 +00:00
|
|
|
'mycompany.com/gitlab',
|
|
|
|
'gitlab.mycompany.com',
|
|
|
|
'othercompany.com/nested/gitlab',
|
|
|
|
'gitlab.com',
|
|
|
|
'gitlab.mycompany.local',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2022-02-23 15:57:47 +00:00
|
|
|
]);
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->disableOriginalConstructor()->getMock();
|
|
|
|
$this->process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
|
|
|
|
$this->httpDownloader = $this->getHttpDownloaderMock();
|
2015-02-20 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
protected function tearDown(): void
|
2016-01-21 12:01:55 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2016-01-21 12:01:55 +00:00
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs->removeDirectory($this->home);
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function provideInitializeUrls(): array
|
2015-02-20 22:12:48 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'],
|
|
|
|
['http://gitlab.com/mygroup/myproject', 'http://gitlab.com/api/v4/projects/mygroup%2Fmyproject'],
|
|
|
|
['git@gitlab.com:mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'],
|
|
|
|
];
|
2015-11-14 15:00:14 +00:00
|
|
|
}
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2015-11-14 15:00:14 +00:00
|
|
|
/**
|
2021-10-27 13:29:52 +00:00
|
|
|
* @dataProvider provideInitializeUrls
|
2022-10-11 14:51:47 +00:00
|
|
|
* @param non-empty-string $url
|
|
|
|
* @param non-empty-string $apiUrl
|
2015-11-14 15:00:14 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testInitialize(string $url, string $apiUrl): GitLabDriver
|
2015-11-14 15:00:14 +00:00
|
|
|
{
|
2015-02-20 22:12:48 +00:00
|
|
|
// @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
|
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
2017-08-07 11:03:02 +00:00
|
|
|
"visibility": "private",
|
2021-12-22 09:54:48 +00:00
|
|
|
"issues_enabled": true,
|
|
|
|
"archived": false,
|
2015-02-20 22:12:48 +00:00
|
|
|
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
|
|
|
|
"ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/myproject",
|
|
|
|
"web_url": "https://gitlab.com/mygroup/myproject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2014-10-21 08:25:24 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2015-02-20 22:12:48 +00:00
|
|
|
$driver->initialize();
|
2014-10-21 08:25:24 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
|
|
|
self::assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
|
|
|
|
self::assertEquals('git@gitlab.com:mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
|
|
|
|
self::assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl());
|
2014-10-21 08:25:24 +00:00
|
|
|
|
2015-02-20 22:12:48 +00:00
|
|
|
return $driver;
|
2014-10-21 08:25:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 02:38:59 +00:00
|
|
|
/**
|
2021-10-27 13:29:52 +00:00
|
|
|
* @dataProvider provideInitializeUrls
|
2022-10-11 14:51:47 +00:00
|
|
|
* @param non-empty-string $url
|
|
|
|
* @param non-empty-string $apiUrl
|
2016-08-12 02:38:59 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testInitializePublicProject(string $url, string $apiUrl): GitLabDriver
|
2016-08-12 02:38:59 +00:00
|
|
|
{
|
|
|
|
// @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
|
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
2017-08-07 11:03:02 +00:00
|
|
|
"visibility": "public",
|
2016-08-12 02:38:59 +00:00
|
|
|
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
|
|
|
|
"ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
2017-08-31 17:14:41 +00:00
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/myproject",
|
|
|
|
"web_url": "https://gitlab.com/mygroup/myproject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2017-08-31 17:14:41 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2017-08-31 17:14:41 +00:00
|
|
|
$driver->initialize();
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
|
|
|
self::assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
|
|
|
|
self::assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
|
|
|
|
self::assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl());
|
2017-08-31 17:14:41 +00:00
|
|
|
|
|
|
|
return $driver;
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:02:48 +00:00
|
|
|
/**
|
2021-10-27 13:29:52 +00:00
|
|
|
* @dataProvider provideInitializeUrls
|
2022-10-11 14:51:47 +00:00
|
|
|
* @param non-empty-string $url
|
|
|
|
* @param non-empty-string $apiUrl
|
2017-12-18 15:02:48 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testInitializePublicProjectAsAnonymous(string $url, string $apiUrl): GitLabDriver
|
2017-12-18 15:02:48 +00:00
|
|
|
{
|
|
|
|
// @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
|
|
|
|
$projectData = <<<JSON
|
2017-08-31 17:14:41 +00:00
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
|
|
|
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
|
|
|
|
"ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
2016-08-12 02:38:59 +00:00
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/myproject",
|
|
|
|
"web_url": "https://gitlab.com/mygroup/myproject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2016-08-12 02:38:59 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2016-08-12 02:38:59 +00:00
|
|
|
$driver->initialize();
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
|
|
|
self::assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
|
|
|
|
self::assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
|
|
|
|
self::assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl());
|
2016-08-12 02:38:59 +00:00
|
|
|
|
|
|
|
return $driver;
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:40:53 +00:00
|
|
|
/**
|
|
|
|
* Also support repositories over HTTP (TLS) and has a port number.
|
|
|
|
*
|
|
|
|
* @group gitlabHttpPort
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInitializeWithPortNumber(): void
|
2017-12-12 02:40:53 +00:00
|
|
|
{
|
|
|
|
$domain = 'gitlab.mycompany.com';
|
|
|
|
$port = '5443';
|
|
|
|
$namespace = 'mygroup/myproject';
|
|
|
|
$url = sprintf('https://%1$s:%2$s/%3$s', $domain, $port, $namespace);
|
|
|
|
$apiUrl = sprintf('https://%1$s:%2$s/api/v4/projects/%3$s', $domain, $port, urlencode($namespace));
|
|
|
|
|
|
|
|
// An incomplete single project API response payload.
|
|
|
|
// @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
|
|
|
|
$projectData = <<<'JSON'
|
|
|
|
{
|
|
|
|
"default_branch": "1.0.x",
|
|
|
|
"http_url_to_repo": "https://%1$s:%2$s/%3$s.git",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "%3$s",
|
|
|
|
"web_url": "https://%1$s:%2$s/%3$s"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => sprintf($projectData, $domain, $port, $namespace)]],
|
|
|
|
true
|
|
|
|
);
|
2017-12-12 02:40:53 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2017-12-12 02:40:53 +00:00
|
|
|
$driver->initialize();
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
|
|
|
self::assertEquals('1.0.x', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
|
|
|
|
self::assertEquals($url.'.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
|
|
|
|
self::assertEquals($url, $driver->getUrl());
|
2017-12-12 02:40:53 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 19:18:19 +00:00
|
|
|
public function testInvalidSupportData(): void
|
|
|
|
{
|
|
|
|
$driver = $this->testInitialize($repoUrl = 'https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
|
|
|
$this->setAttribute($driver, 'branches', ['main' => 'SOMESHA']);
|
|
|
|
$this->setAttribute($driver, 'tags', []);
|
|
|
|
|
|
|
|
$this->httpDownloader->expects([
|
|
|
|
['url' => 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/files/composer%2Ejson/raw?ref=SOMESHA', 'body' => '{"support": "'.$repoUrl.'" }'],
|
|
|
|
], true);
|
|
|
|
|
|
|
|
$data = $driver->getComposerInformation('main');
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertIsArray($data);
|
|
|
|
self::assertSame('https://gitlab.com/mygroup/myproject/-/tree/main', $data['support']['source']);
|
2023-03-20 19:18:19 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetDist(): void
|
2014-10-21 08:25:24 +00:00
|
|
|
{
|
2017-08-07 11:03:02 +00:00
|
|
|
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
2015-11-14 15:00:14 +00:00
|
|
|
|
2015-02-20 22:12:48 +00:00
|
|
|
$reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2015-02-20 22:12:48 +00:00
|
|
|
'type' => 'zip',
|
2017-08-07 11:03:02 +00:00
|
|
|
'url' => 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/archive.zip?sha='.$reference,
|
2015-02-20 22:12:48 +00:00
|
|
|
'reference' => $reference,
|
|
|
|
'shasum' => '',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2014-10-21 08:25:24 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $driver->getDist($reference));
|
2015-02-20 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetSource(): void
|
2015-02-20 22:12:48 +00:00
|
|
|
{
|
2017-08-07 11:03:02 +00:00
|
|
|
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
2015-11-14 15:00:14 +00:00
|
|
|
|
2015-02-20 22:12:48 +00:00
|
|
|
$reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2015-02-20 22:12:48 +00:00
|
|
|
'type' => 'git',
|
|
|
|
'url' => 'git@gitlab.com:mygroup/myproject.git',
|
|
|
|
'reference' => $reference,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $driver->getSource($reference));
|
2015-02-20 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetSource_GivenPublicProject(): void
|
2016-08-12 02:38:59 +00:00
|
|
|
{
|
2018-11-12 14:23:32 +00:00
|
|
|
$driver = $this->testInitializePublicProject('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
2016-08-12 02:38:59 +00:00
|
|
|
|
|
|
|
$reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2016-08-12 02:38:59 +00:00
|
|
|
'type' => 'git',
|
|
|
|
'url' => 'https://gitlab.com/mygroup/myproject.git',
|
|
|
|
'reference' => $reference,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2016-08-12 02:38:59 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $driver->getSource($reference));
|
2016-08-12 02:38:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetTags(): void
|
2015-02-20 22:12:48 +00:00
|
|
|
{
|
2017-08-07 11:03:02 +00:00
|
|
|
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
2015-11-14 15:00:14 +00:00
|
|
|
|
2017-08-08 08:26:35 +00:00
|
|
|
$apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?per_page=100';
|
2015-02-20 22:12:48 +00:00
|
|
|
|
|
|
|
// @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-tags
|
|
|
|
$tagData = <<<JSON
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "v1.0.0",
|
|
|
|
"commit": {
|
|
|
|
"id": "092ed2c762bbae331e3f51d4a17f67310bf99a81",
|
|
|
|
"committed_date": "2012-05-28T04:42:42-07:00"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "v2.0.0",
|
|
|
|
"commit": {
|
|
|
|
"id": "8e8f60b3ec86d63733db3bd6371117a758027ec6",
|
|
|
|
"committed_date": "2014-07-06T12:59:11.000+02:00"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $tagData]],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$driver->setHttpDownloader($this->httpDownloader);
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2015-02-20 22:12:48 +00:00
|
|
|
'v1.0.0' => '092ed2c762bbae331e3f51d4a17f67310bf99a81',
|
|
|
|
'v2.0.0' => '8e8f60b3ec86d63733db3bd6371117a758027ec6',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $driver->getTags());
|
|
|
|
self::assertEquals($expected, $driver->getTags(), 'Tags are cached');
|
2015-02-20 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetPaginatedRefs(): void
|
2017-12-18 15:02:48 +00:00
|
|
|
{
|
2017-08-07 19:46:43 +00:00
|
|
|
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
|
|
|
|
|
|
|
// @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches
|
2022-08-17 12:20:07 +00:00
|
|
|
$branchData = [
|
|
|
|
[
|
2017-08-18 12:14:15 +00:00
|
|
|
"name" => "mymaster",
|
2022-08-17 12:20:07 +00:00
|
|
|
"commit" => [
|
2017-08-18 12:14:15 +00:00
|
|
|
"id" => "97eda36b5c1dd953a3792865c222d4e85e5f302e",
|
2017-12-18 15:02:48 +00:00
|
|
|
"committed_date" => "2013-01-03T21:04:07.000+01:00",
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2017-08-18 12:14:15 +00:00
|
|
|
"name" => "staging",
|
2022-08-17 12:20:07 +00:00
|
|
|
"commit" => [
|
2017-08-18 12:14:15 +00:00
|
|
|
"id" => "502cffe49f136443f2059803f2e7192d1ac066cd",
|
2017-12-18 15:02:48 +00:00
|
|
|
"committed_date" => "2013-03-09T16:35:23.000+01:00",
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2017-08-18 12:14:15 +00:00
|
|
|
|
|
|
|
for ($i = 0; $i < 98; $i++) {
|
2022-08-17 12:20:07 +00:00
|
|
|
$branchData[] = [
|
2017-08-18 12:14:15 +00:00
|
|
|
"name" => "stagingdupe",
|
2022-08-17 12:20:07 +00:00
|
|
|
"commit" => [
|
2017-08-18 12:14:15 +00:00
|
|
|
"id" => "502cffe49f136443f2059803f2e7192d1ac066cd",
|
2017-12-18 15:02:48 +00:00
|
|
|
"committed_date" => "2013-03-09T16:35:23.000+01:00",
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
];
|
2017-08-07 19:46:43 +00:00
|
|
|
}
|
2017-08-18 12:14:15 +00:00
|
|
|
|
2021-12-09 21:14:04 +00:00
|
|
|
$branchData = JsonFile::encode($branchData);
|
2017-08-07 19:46:43 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'url' => 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches?per_page=100',
|
|
|
|
'body' => $branchData,
|
2022-08-17 12:20:07 +00:00
|
|
|
'headers' => ['Link: <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20>; rel="next", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=1&per_page=20>; rel="first", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=3&per_page=20>; rel="last"'],
|
2021-12-09 16:09:07 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'url' => "http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20",
|
|
|
|
'body' => $branchData,
|
2022-08-17 12:20:07 +00:00
|
|
|
'headers' => ['Link: <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20>; rel="prev", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=1&per_page=20>; rel="first", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=3&per_page=20>; rel="last"'],
|
2021-12-09 16:09:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2017-08-07 19:46:43 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$driver->setHttpDownloader($this->httpDownloader);
|
2017-08-07 19:46:43 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2017-08-07 19:46:43 +00:00
|
|
|
'mymaster' => '97eda36b5c1dd953a3792865c222d4e85e5f302e',
|
|
|
|
'staging' => '502cffe49f136443f2059803f2e7192d1ac066cd',
|
2017-08-18 12:14:15 +00:00
|
|
|
'stagingdupe' => '502cffe49f136443f2059803f2e7192d1ac066cd',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2017-08-07 19:46:43 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $driver->getBranches());
|
|
|
|
self::assertEquals($expected, $driver->getBranches(), 'Branches are cached');
|
2017-08-07 19:46:43 +00:00
|
|
|
}
|
2017-12-18 15:02:48 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetBranches(): void
|
2015-02-20 22:12:48 +00:00
|
|
|
{
|
2017-08-07 11:03:02 +00:00
|
|
|
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
|
2015-11-14 15:00:14 +00:00
|
|
|
|
2017-08-08 08:26:35 +00:00
|
|
|
$apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches?per_page=100';
|
2015-02-20 22:12:48 +00:00
|
|
|
|
|
|
|
// @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches
|
|
|
|
$branchData = <<<JSON
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "mymaster",
|
|
|
|
"commit": {
|
|
|
|
"id": "97eda36b5c1dd953a3792865c222d4e85e5f302e",
|
|
|
|
"committed_date": "2013-01-03T21:04:07.000+01:00"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "staging",
|
|
|
|
"commit": {
|
|
|
|
"id": "502cffe49f136443f2059803f2e7192d1ac066cd",
|
|
|
|
"committed_date": "2013-03-09T16:35:23.000+01:00"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $branchData]],
|
|
|
|
true
|
|
|
|
);
|
2017-08-07 19:46:43 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$driver->setHttpDownloader($this->httpDownloader);
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [
|
2015-02-20 22:12:48 +00:00
|
|
|
'mymaster' => '97eda36b5c1dd953a3792865c222d4e85e5f302e',
|
2017-03-08 14:07:29 +00:00
|
|
|
'staging' => '502cffe49f136443f2059803f2e7192d1ac066cd',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2015-02-20 22:12:48 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $driver->getBranches());
|
|
|
|
self::assertEquals($expected, $driver->getBranches(), 'Branches are cached');
|
2015-02-20 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-12 02:40:53 +00:00
|
|
|
* @group gitlabHttpPort
|
2015-02-20 22:12:48 +00:00
|
|
|
* @dataProvider dataForTestSupports
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testSupports(string $url, bool $expected): void
|
2015-02-20 22:12:48 +00:00
|
|
|
{
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, GitLabDriver::supports($this->io, $this->config, $url));
|
2015-02-20 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function dataForTestSupports(): array
|
2015-02-20 22:12:48 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['http://gitlab.com/foo/bar', true],
|
|
|
|
['http://gitlab.mycompany.com:5443/foo/bar', true],
|
|
|
|
['http://gitlab.com/foo/bar/', true],
|
|
|
|
['http://gitlab.com/foo/bar/', true],
|
|
|
|
['http://gitlab.com/foo/bar.git', true],
|
|
|
|
['http://gitlab.com/foo/bar.git', true],
|
|
|
|
['http://gitlab.com/foo/bar.baz.git', true],
|
|
|
|
['https://gitlab.com/foo/bar', extension_loaded('openssl')], // Platform requirement
|
|
|
|
['https://gitlab.mycompany.com:5443/foo/bar', extension_loaded('openssl')], // Platform requirement
|
|
|
|
['git@gitlab.com:foo/bar.git', extension_loaded('openssl')],
|
|
|
|
['git@example.com:foo/bar.git', false],
|
|
|
|
['http://example.com/foo/bar', false],
|
|
|
|
['http://mycompany.com/gitlab/mygroup/myproject', true],
|
|
|
|
['https://mycompany.com/gitlab/mygroup/myproject', extension_loaded('openssl')],
|
|
|
|
['http://othercompany.com/nested/gitlab/mygroup/myproject', true],
|
|
|
|
['https://othercompany.com/nested/gitlab/mygroup/myproject', extension_loaded('openssl')],
|
|
|
|
['http://gitlab.com/mygroup/mysubgroup/mysubsubgroup/myproject', true],
|
|
|
|
['https://gitlab.com/mygroup/mysubgroup/mysubsubgroup/myproject', extension_loaded('openssl')],
|
|
|
|
];
|
2014-10-21 08:25:24 +00:00
|
|
|
}
|
2015-11-23 20:53:35 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGitlabSubDirectory(): void
|
2015-11-23 20:53:35 +00:00
|
|
|
{
|
2017-01-27 17:01:24 +00:00
|
|
|
$url = 'https://mycompany.com/gitlab/mygroup/my-pro.ject';
|
2017-08-07 11:03:02 +00:00
|
|
|
$apiUrl = 'https://mycompany.com/gitlab/api/v4/projects/mygroup%2Fmy-pro%2Eject';
|
2015-11-23 20:53:35 +00:00
|
|
|
|
2017-03-08 09:26:08 +00:00
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
2017-08-07 11:03:02 +00:00
|
|
|
"visibility": "private",
|
2017-04-24 08:08:31 +00:00
|
|
|
"http_url_to_repo": "https://gitlab.com/gitlab/mygroup/my-pro.ject",
|
2017-03-08 09:26:08 +00:00
|
|
|
"ssh_url_to_repo": "git@gitlab.com:mygroup/my-pro.ject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/my-pro.ject",
|
2017-04-24 08:08:31 +00:00
|
|
|
"web_url": "https://gitlab.com/gitlab/mygroup/my-pro.ject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2017-04-24 08:08:31 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2017-04-24 08:08:31 +00:00
|
|
|
$driver->initialize();
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
2017-04-24 08:08:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGitlabSubGroup(): void
|
2017-04-24 08:08:31 +00:00
|
|
|
{
|
|
|
|
$url = 'https://gitlab.com/mygroup/mysubgroup/myproject';
|
2017-08-07 11:03:02 +00:00
|
|
|
$apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmysubgroup%2Fmyproject';
|
2017-04-24 08:08:31 +00:00
|
|
|
|
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
2017-08-07 11:03:02 +00:00
|
|
|
"visibility": "private",
|
2017-04-24 08:08:31 +00:00
|
|
|
"http_url_to_repo": "https://gitlab.com/mygroup/mysubgroup/my-pro.ject",
|
|
|
|
"ssh_url_to_repo": "git@gitlab.com:mygroup/mysubgroup/my-pro.ject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/mysubgroup/my-pro.ject",
|
|
|
|
"web_url": "https://gitlab.com/mygroup/mysubgroup/my-pro.ject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2017-04-24 08:08:31 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2017-04-24 08:08:31 +00:00
|
|
|
$driver->initialize();
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
2017-04-24 08:08:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGitlabSubDirectorySubGroup(): void
|
2017-04-24 08:08:31 +00:00
|
|
|
{
|
|
|
|
$url = 'https://mycompany.com/gitlab/mygroup/mysubgroup/myproject';
|
2017-08-07 11:03:02 +00:00
|
|
|
$apiUrl = 'https://mycompany.com/gitlab/api/v4/projects/mygroup%2Fmysubgroup%2Fmyproject';
|
2017-04-24 08:08:31 +00:00
|
|
|
|
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
2017-08-07 11:03:02 +00:00
|
|
|
"visibility": "private",
|
2017-04-24 08:08:31 +00:00
|
|
|
"http_url_to_repo": "https://mycompany.com/gitlab/mygroup/mysubgroup/my-pro.ject",
|
|
|
|
"ssh_url_to_repo": "git@mycompany.com:mygroup/mysubgroup/my-pro.ject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/mysubgroup/my-pro.ject",
|
|
|
|
"web_url": "https://mycompany.com/gitlab/mygroup/mysubgroup/my-pro.ject"
|
2017-03-08 09:26:08 +00:00
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2017-03-08 09:26:08 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $this->config, $this->httpDownloader, $this->process);
|
2015-11-23 20:53:35 +00:00
|
|
|
$driver->initialize();
|
2017-03-08 09:26:08 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
|
2015-11-23 20:53:35 +00:00
|
|
|
}
|
2017-04-26 14:59:50 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testForwardsOptions(): void
|
2017-04-26 14:59:50 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$options = [
|
|
|
|
'ssl' => [
|
2017-04-26 14:59:50 +00:00
|
|
|
'verify_peer' => false,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
];
|
2017-04-26 14:59:50 +00:00
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
2017-08-07 11:03:02 +00:00
|
|
|
"visibility": "private",
|
2017-04-26 14:59:50 +00:00
|
|
|
"http_url_to_repo": "https://gitlab.mycompany.local/mygroup/myproject",
|
|
|
|
"ssh_url_to_repo": "git@gitlab.mycompany.local:mygroup/myproject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/myproject",
|
|
|
|
"web_url": "https://gitlab.mycompany.local/mygroup/myproject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
2022-02-23 15:57:47 +00:00
|
|
|
[['url' => 'https://gitlab.mycompany.local/api/v4/projects/mygroup%2Fmyproject', 'body' => $projectData]],
|
2021-12-09 16:09:07 +00:00
|
|
|
true
|
|
|
|
);
|
2017-04-26 14:59:50 +00:00
|
|
|
|
|
|
|
$driver = new GitLabDriver(
|
2022-08-17 12:20:07 +00:00
|
|
|
['url' => 'https://gitlab.mycompany.local/mygroup/myproject', 'options' => $options],
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->io,
|
2017-04-26 14:59:50 +00:00
|
|
|
$this->config,
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader,
|
|
|
|
$this->process
|
2017-04-26 14:59:50 +00:00
|
|
|
);
|
|
|
|
$driver->initialize();
|
|
|
|
}
|
2018-10-31 11:44:54 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testProtocolOverrideRepositoryUrlGeneration(): void
|
2021-05-27 21:05:53 +00:00
|
|
|
{
|
|
|
|
// @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
|
|
|
|
$projectData = <<<JSON
|
|
|
|
{
|
|
|
|
"id": 17,
|
|
|
|
"default_branch": "mymaster",
|
|
|
|
"visibility": "private",
|
|
|
|
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
|
|
|
|
"ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
|
|
|
|
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
|
|
|
|
"name": "My Project",
|
|
|
|
"name_with_namespace": "My Group / My Project",
|
|
|
|
"path": "myproject",
|
|
|
|
"path_with_namespace": "mygroup/myproject",
|
|
|
|
"web_url": "https://gitlab.com/mygroup/myproject"
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
|
|
|
|
$apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject';
|
|
|
|
$url = 'git@gitlab.com:mygroup/myproject';
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->httpDownloader->expects(
|
|
|
|
[['url' => $apiUrl, 'body' => $projectData]],
|
|
|
|
true
|
|
|
|
);
|
2021-05-27 21:05:53 +00:00
|
|
|
|
|
|
|
$config = clone $this->config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['gitlab-protocol' => 'http']]);
|
|
|
|
$driver = new GitLabDriver(['url' => $url], $this->io, $config, $this->httpDownloader, $this->process);
|
2021-05-27 21:05:53 +00:00
|
|
|
$driver->initialize();
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'Repository URL matches config request for http not git');
|
2021-05-27 21:05:53 +00:00
|
|
|
}
|
2023-03-20 19:18:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param object $object
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
protected function setAttribute($object, string $attribute, $value): void
|
|
|
|
{
|
|
|
|
$attr = new \ReflectionProperty($object, $attribute);
|
|
|
|
$attr->setAccessible(true);
|
|
|
|
$attr->setValue($object, $value);
|
|
|
|
}
|
2014-10-21 08:25:24 +00:00
|
|
|
}
|