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