‪TYPO3CMS  10.4
PackageTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use org\bovigo\vfs\vfsStream;
22 use TYPO3\CMS\Core\Package\PackageManager;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪PackageTest extends UnitTestCase
29 {
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  vfsStream::setup('Packages');
34  }
35 
40  {
41  $this->expectException(InvalidPackagePathException::class);
42  $this->expectExceptionCode(1166631890);
43 
44  $packageManagerMock = $this->createMock(PackageManager::class);
45  $packageManagerMock->expects(self::any())->method('isPackageKeyValid')->willReturn(true);
46  new ‪Package($packageManagerMock, 'Vendor.TestPackage', './ThisPackageSurelyDoesNotExist');
47  }
48 
49  public function ‪validPackageKeys()
50  {
51  return [
52  ['Doctrine.DBAL'],
53  ['TYPO3.CMS'],
54  ['My.Own.TwitterPackage'],
55  ['GoFor.IT'],
56  ['Symfony.Symfony']
57  ];
58  }
59 
64  public function ‪constructAcceptsValidPackageKeys($packageKey)
65  {
66  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
67  mkdir($packagePath, 0777, true);
68  file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
69  file_put_contents($packagePath . 'ext_emconf.php', '');
70 
71  $packageManagerMock = $this->createMock(PackageManager::class);
72  $packageManagerMock->expects(self::any())->method('isPackageKeyValid')->willReturn(true);
73  $package = new ‪Package($packageManagerMock, $packageKey, $packagePath);
74  self::assertEquals($packageKey, $package->getPackageKey());
75  }
76 
77  public function ‪invalidPackageKeys()
78  {
79  return [
80  ['TYPO3..Flow'],
81  ['RobertLemke.Flow. Twitter'],
82  ['Schalke*4']
83  ];
84  }
85 
90  public function ‪constructRejectsInvalidPackageKeys($packageKey)
91  {
92  $this->expectException(InvalidPackageKeyException::class);
93  $this->expectExceptionCode(1217959511);
94 
95  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
96  mkdir($packagePath, 0777, true);
97 
98  $packageManagerMock = $this->createMock(PackageManager::class);
99  new ‪Package($packageManagerMock, $packageKey, $packagePath);
100  }
101 
106  {
107  $packagePath = 'vfs://Packages/Application/Vendor/Dummy/';
108  mkdir($packagePath, 0700, true);
109  file_put_contents($packagePath . 'composer.json', '{"name": "vendor/dummy", "type": "flow-test"}');
110  file_put_contents($packagePath . 'ext_emconf.php', '');
111 
112  $packageManagerMock = $this->createMock(PackageManager::class);
113  $packageManagerMock->expects(self::any())->method('isPackageKeyValid')->willReturn(true);
114  $package = new ‪Package($packageManagerMock, 'Vendor.Dummy', $packagePath);
115 
116  self::assertFalse($package->isProtected());
117  $package->setProtected(true);
118  self::assertTrue($package->isProtected());
119  }
120 }
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\setUp
‪setUp()
Definition: PackageTest.php:30
‪TYPO3\CMS\Core\Package\Exception\InvalidPackagePathException
Definition: InvalidPackagePathException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\invalidPackageKeys
‪invalidPackageKeys()
Definition: PackageTest.php:77
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\constructThrowsPackageDoesNotExistException
‪constructThrowsPackageDoesNotExistException()
Definition: PackageTest.php:39
‪TYPO3\CMS\Core\Package\Exception\InvalidPackageKeyException
Definition: InvalidPackageKeyException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest
Definition: PackageTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\constructRejectsInvalidPackageKeys
‪constructRejectsInvalidPackageKeys($packageKey)
Definition: PackageTest.php:90
‪TYPO3\CMS\Core\Tests\Unit\Package
Definition: AbstractServiceProviderTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\constructAcceptsValidPackageKeys
‪constructAcceptsValidPackageKeys($packageKey)
Definition: PackageTest.php:64
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:26
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\aPackageCanBeFlaggedAsProtected
‪aPackageCanBeFlaggedAsProtected()
Definition: PackageTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Package\PackageTest\validPackageKeys
‪validPackageKeys()
Definition: PackageTest.php:49