Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FileWriterGeneratorStrategyTest.php
001 <?php
002 /*
003 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
004 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
005 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
006 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
007 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
008 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
009 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
010 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
011 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
012 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
013 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014 *
015 * This software consists of voluntary contributions made by many individuals
016 * and is licensed under the MIT license.
017 */
018
019 namespace ProxyManagerTest\GeneratorStrategy;
020
021 use PHPUnit_Framework_TestCase;
022 use ProxyManager\Exception\FileNotWritableException;
023 use ProxyManager\Generator\ClassGenerator;
024 use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
025 use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy;
026
027 /**
028 * Tests for {@see \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy}
029 *
030 * @author Marco Pivetta <ocramius@gmail.com>
031 * @license MIT
032 *
033 * @group Coverage
034 *
035 * Note: this test generates temporary files that are not deleted
036 */
037 class FileWriterGeneratorStrategyTest extends PHPUnit_Framework_TestCase
038 {
039 /**
040 * @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::__construct
041 * @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::generate
042 */
043 public function testGenerate()
044 {
045 /* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
046 $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
047 $generator = new FileWriterGeneratorStrategy($locator);
048 $tmpFile = sys_get_temp_dir() . '/' . uniqid('FileWriterGeneratorStrategyTest', true) . '.php';
049 $namespace = 'Foo';
050 $className = UniqueIdentifierGenerator::getIdentifier('Bar');
051 $fqcn = $namespace . '\\' . $className;
052
053 $locator
054 ->expects($this->any())
055 ->method('getProxyFileName')
056 ->with($fqcn)
057 ->will($this->returnValue($tmpFile));
058
059 $body = $generator->generate(new ClassGenerator($fqcn));
060
061 $this->assertGreaterThan(0, strpos($body, $className));
062 $this->assertFalse(class_exists($fqcn, false));
063 $this->assertTrue(file_exists($tmpFile));
064
065 require $tmpFile;
066
067 $this->assertTrue(class_exists($fqcn, false));
068 }
069
070 public function testGenerateWillFailIfTmpFileCannotBeWrittenToDisk()
071 {
072 $tmpDirPath = sys_get_temp_dir() . '/' . uniqid('nonWritable', true);
073
074 mkdir($tmpDirPath, 0555, true);
075
076 /* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
077 $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
078 $generator = new FileWriterGeneratorStrategy($locator);
079 $tmpFile = $tmpDirPath . '/' . uniqid('FileWriterGeneratorStrategyFailedFileWriteTest', true) . '.php';
080 $namespace = 'Foo';
081 $className = UniqueIdentifierGenerator::getIdentifier('Bar');
082 $fqcn = $namespace . '\\' . $className;
083
084 $locator
085 ->expects($this->any())
086 ->method('getProxyFileName')
087 ->with($fqcn)
088 ->will($this->returnValue($tmpFile));
089
090 $this->setExpectedException('ProxyManager\\Exception\\FileNotWritableException');
091 $generator->generate(new ClassGenerator($fqcn));
092 }
093
094 public function testGenerateWillFailIfTmpFileCannotBeMovedToFinalDestination()
095 {
096 /* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
097 $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
098 $generator = new FileWriterGeneratorStrategy($locator);
099 $tmpFile = sys_get_temp_dir() . '/' . uniqid('FileWriterGeneratorStrategyFailedFileMoveTest', true) . '.php';
100 $namespace = 'Foo';
101 $className = UniqueIdentifierGenerator::getIdentifier('Bar');
102 $fqcn = $namespace . '\\' . $className;
103
104 $locator
105 ->expects($this->any())
106 ->method('getProxyFileName')
107 ->with($fqcn)
108 ->will($this->returnValue($tmpFile));
109
110 mkdir($tmpFile);
111
112 $this->setExpectedException('ProxyManager\\Exception\\FileNotWritableException');
113 $generator->generate(new ClassGenerator($fqcn));
114 }
115
116 public function testWhenFailingAllTemporaryFilesAreRemoved()
117 {
118 $tmpDirPath = sys_get_temp_dir() . '/' . uniqid('noTempFilesLeftBehind', true);
119
120 mkdir($tmpDirPath);
121
122 /* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
123 $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
124 $generator = new FileWriterGeneratorStrategy($locator);
125 $tmpFile = $tmpDirPath . '/' . uniqid('FileWriterGeneratorStrategyFailedFileMoveTest', true) . '.php';
126 $namespace = 'Foo';
127 $className = UniqueIdentifierGenerator::getIdentifier('Bar');
128 $fqcn = $namespace . '\\' . $className;
129
130 $locator
131 ->expects($this->any())
132 ->method('getProxyFileName')
133 ->with($fqcn)
134 ->will($this->returnValue($tmpFile));
135
136 mkdir($tmpFile);
137
138 try {
139 $generator->generate(new ClassGenerator($fqcn));
140
141 $this->fail('An exception was supposed to be thrown');
142 } catch (FileNotWritableException $exception) {
143 rmdir($tmpFile);
144
145 $this->assertEquals(array('.', '..'), scandir($tmpDirPath));
146 }
147 }
148 }
149