Completed
Push — master ( c9de9a...8fa92c )
by Joschi
06:37
created

ObjectTest::testPersistEarlierRevision()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 2
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Infrastructure
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Tests {
38
39
    use Apparat\Kernel\Ports\Kernel;
40
    use Apparat\Object\Application\Factory\ObjectFactory;
41
    use Apparat\Object\Application\Model\Object\Article;
42
    use Apparat\Object\Domain\Model\Object\AbstractObject;
43
    use Apparat\Object\Domain\Model\Object\Id;
44
    use Apparat\Object\Domain\Model\Object\ResourceInterface;
45
    use Apparat\Object\Domain\Model\Object\Revision;
46
    use Apparat\Object\Domain\Model\Object\Type;
47
    use Apparat\Object\Domain\Model\Path\RepositoryPath;
48
    use Apparat\Object\Domain\Model\Properties\SystemProperties;
49
    use Apparat\Object\Domain\Repository\Repository;
50
    use Apparat\Object\Infrastructure\Repository\FileAdapterStrategy;
51
    use Apparat\Object\Ports\Object;
52
    use Apparat\Object\Ports\Repository as RepositoryFactory;
53
    use Prophecy\Prophecy\Revealer;
54
55
    /**
56
     * Object tests
57
     *
58
     * @package Apparat\Object
59
     * @subpackage Apparat\Object\Test
60
     */
61
    class ObjectTest extends AbstractRepositoryEnabledTest
62
    {
63
        /**
64
         * Example object path
65
         *
66
         * @var string
67
         */
68
        const OBJECT_PATH = '/2015/12/21/1-article/1';
69
        /**
70
         * Example hidden object path
71
         *
72
         * @var string
73
         */
74
        const HIDDEN_OBJECT_PATH = '/2016/05/26/6-article/6';
75
76
        /**
77
         * Tears down the fixture
78
         */
79
        public function tearDown()
80
        {
81
            putenv('MOCK_FLOCK');
82
            putenv('MOCK_RENAME');
83
            TestType::removeInvalidType();
84
            parent::tearDown();
85
        }
86
87
        /**
88
         * Test undefined object type
89
         *
90
         * @expectedException \Apparat\Object\Application\Factory\InvalidArgumentException
91
         * @expectedExceptionCode 1450905868
92
         */
93
        public function testUndefinedObjectType()
94
        {
95
            $resource = $this->getMock(ResourceInterface::class);
96
            $resource->method('getPropertyData')->willReturn([]);
97
            $repositoryPath = $this->getMockBuilder(RepositoryPath::class)->disableOriginalConstructor()->getMock();
98
99
            /** @var ResourceInterface $resource */
100
            /** @var RepositoryPath $repositoryPath */
101
            ObjectFactory::createFromResource($repositoryPath, $resource);
102
        }
103
104
        /**
105
         * Test invalid object type
106
         *
107
         * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
108
         * @expectedExceptionCode 1449871242
109
         */
110
        public function testInvalidObjectType()
111
        {
112
            $resource = $this->getMock(ResourceInterface::class);
113
            $resource->method('getPropertyData')->willReturn([SystemProperties::COLLECTION => ['type' => 'invalid']]);
114
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
115
116
            /** @var ResourceInterface $resource */
117
            ObjectFactory::createFromResource($articleObjectPath, $resource);
118
        }
119
120
        /**
121
         * Load an article object with an invalid visibility requirement
122
         *
123
         * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
124
         * @expectedExceptionCode 1449999646
125
         */
126
        public function testLoadArticleObjectInvalidVisibility()
127
        {
128
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
129
            self::$repository->loadObject($articleObjectPath, 0);
130
        }
131
132
        /**
133
         * Load an article object
134
         *
135
         * @expectedException \Apparat\Object\Domain\Model\Object\OutOfBoundsException
136
         * @expectedExceptionCode 1461619783
137
         */
138
        public function testLoadArticleObject()
139
        {
140
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
141
            $articleObject = self::$repository->loadObject($articleObjectPath);
142
            $this->assertEquals(
143
                getenv('APPARAT_BASE_URL').getenv('REPOSITORY_URL').self::OBJECT_PATH,
144
                $articleObject->getAbsoluteUrl()
145
            );
146
            $this->assertFalse($articleObject->isDeleted());
147
            $this->assertFalse($articleObject->getRepositoryPath()->isHidden());
148
149
            /** @var Revision $invalidRevision */
150
            $invalidRevision = Kernel::create(Revision::class, [99]);
151
            $articleObject->useRevision($invalidRevision);
152
        }
153
154
        /**
155
         * Load a hidden article object
156
         */
157
        public function testLoadHiddenArticleObject()
158
        {
159
            $articleObjectPath = new RepositoryPath(self::$repository, self::HIDDEN_OBJECT_PATH);
160
            $articleObject = self::$repository->loadObject($articleObjectPath);
161
            $this->assertTrue($articleObject->isDeleted());
162
            $this->assertTrue($articleObject->getRepositoryPath()->isHidden());
163
        }
164
165
        /**
166
         * Load an article object and test its system properties
167
         */
168
        public function testLoadArticleObjectSystemProperties()
169
        {
170
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
171
            $articleObject = self::$repository->loadObject($articleObjectPath);
172
            $this->assertInstanceOf(Article::class, $articleObject);
173
            $this->assertEquals(new Id(1), $articleObject->getId());
174
            $this->assertEquals(new Type(Type::ARTICLE), $articleObject->getType());
175
            $this->assertEquals(new Revision(1), $articleObject->getRevision());
176
            $this->assertFalse($articleObject->isDraft());
177
            $this->assertTrue($articleObject->isPublished());
178
            $this->assertEquals(new \DateTimeImmutable('2015-12-21T22:30:00'), $articleObject->getCreated());
179
            $this->assertEquals(new \DateTimeImmutable('2015-12-21T22:45:00'), $articleObject->getPublished());
180
            $this->assertNull($articleObject->getDeleted());
181
            $this->assertEquals('en', $articleObject->getLanguage());
182
            $this->assertEquals(
183
                "# Example article object\n\nThis file is an example for an object of type `\"article\"`. It has a link to [Joschi Kuphal's website](https://jkphl.is) and features his avatar:\n![Joschi Kuphal](https://jkphl.is/avatar.jpg)\n",
184
                $articleObject->getPayload()
185
            );
186
        }
187
188
        /**
189
         * Load an article object and test its meta properties
190
         */
191
        public function testLoadArticleObjectMetaProperties()
192
        {
193
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
194
            $articleObject = self::$repository->loadObject($articleObjectPath);
195
            $this->assertInstanceOf(Article::class, $articleObject);
196
            $this->assertEquals('Example article object', $articleObject->getDescription());
197
            $this->assertEquals(
198
                'Article objects feature a Markdown payload along with some custom properties',
199
                $articleObject->getAbstract()
200
            );
201
            $this->assertArrayEquals(['apparat', 'object', 'example', 'article'], $articleObject->getKeywords());
202
            $this->assertArrayEquals(['example', 'text'], $articleObject->getCategories());
203
204
            // TODO Replace with contributed-by relations
205
//            $authorCount = count($articleObject->getAuthors());
206
//            $articleObject->addAuthor(AuthorFactory::createFromString(AuthorTest::GENERIC_AUTHOR));
207
//            $this->assertEquals($authorCount + 1, count($articleObject->getAuthors()));
208
        }
209
210
        /**
211
         * Load an article object and test its domain properties
212
         *
213
         * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
214
         * @expectedExceptionCode 1450818168
215
         */
216
        public function testLoadArticleObjectDomainProperties()
217
        {
218
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
219
            $articleObject = self::$repository->loadObject($articleObjectPath);
220
            $this->assertEquals('/system/url', $articleObject->getDomainProperty('uid'));
221
            $this->assertEquals('value', $articleObject->getDomainProperty('group:single'));
222
            $articleObject->getDomainProperty('group:invalid');
223
        }
224
225
        /**
226
         * Load an article object and test an empty domain property name
227
         *
228
         * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
229
         * @expectedExceptionCode 1450817720
230
         */
231
        public function testLoadArticleObjectDomainEmptyProperty()
232
        {
233
            $articleObjectPath = new RepositoryPath(self::$repository, self::OBJECT_PATH);
234
            $articleObject = self::$repository->loadObject($articleObjectPath);
235
            $articleObject->getDomainProperty('');
236
        }
237
238
        /**
239
         * Test the object facade with an absolute object URL
240
         */
241
        public function testObjectFacadeAbsolute()
242
        {
243
            $object = Object::instance(getenv('APPARAT_BASE_URL').getenv('REPOSITORY_URL').self::OBJECT_PATH);
244
            $this->assertInstanceOf(Article::class, $object);
245
        }
246
247
        /**
248
         * Test the object facade with a relative object URL
249
         */
250
        public function testObjectFacadeRelative()
251
        {
252
            $object = Object::instance(getenv('REPOSITORY_URL').self::OBJECT_PATH);
253
            $this->assertInstanceOf(Article::class, $object);
254
        }
255
256
        /**
257
         * Test the object facade with an invalid relative object URL
258
         *
259
         * @expectedException \Apparat\Resource\Ports\InvalidReaderArgumentException
260
         * @expectedExceptionCode 1447616824
261
         */
262
        public function testObjectFacadeRelativeInvalid()
263
        {
264
            $object = Object::instance(getenv('REPOSITORY_URL').'/2015/12/21/2-article/2');
265
            $this->assertInstanceOf(Article::class, $object);
266
        }
267
268
        /**
269
         * Test with a missing object type class
270
         *
271
         * @expectedException \Apparat\Object\Application\Factory\InvalidArgumentException
272
         * @expectedExceptionCode 1450824842
273
         */
274
        public function testInvalidObjectTypeClass()
275
        {
276
            TestType::addInvalidType();
277
278
            $resource = $this->getMock(ResourceInterface::class);
279
            $resource->method('getPropertyData')->willReturn([SystemProperties::COLLECTION => ['type' => 'invalid']]);
280
            $articleObjectPath = new RepositoryPath(self::$repository, '/2016/02/16/5-invalid/5');
281
282
            /** @var ResourceInterface $resource */
283
            ObjectFactory::createFromResource($articleObjectPath, $resource);
284
        }
285
286
        /**
287
         * Test instantiation of object with invalid domain properties collection
288
         *
289
         * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
290
         * @expectedExceptionCode 1452288429
291
         */
292
        public function testInvalidDomainPropertyCollectionClass()
293
        {
294
            $this->getMockBuilder(AbstractObject::class)
295
                ->setConstructorArgs([new RepositoryPath(self::$repository, self::OBJECT_PATH)])
296
                ->getMock();
297
        }
298
299
        /**
300
         * Test the property data
301
         */
302
        public function testObjectPropertyData()
303
        {
304
//  $frontMarkResource = Resource::frontMark('file://'.__DIR__.DIRECTORY_SEPARATOR.'Fixture'.self::OBJECT_PATH.'.md');
305
            $object = Object::instance(getenv('REPOSITORY_URL').self::OBJECT_PATH);
306
            $this->assertTrue(is_array($object->getPropertyData()));
307
//        print_r($frontMarkResource->getData());
308
//        print_r($object->getPropertyData());
309
        }
310
311
        /**
312
         * Test mutation by altering metadata
313
         *
314
         * @expectedException \Apparat\Object\Domain\Model\Properties\OutOfBoundsException
315
         * @expectedExceptionCode 1462632083
316
         */
317
        public function testMetaDataMutation()
318
        {
319
            $object = Object::instance(getenv('REPOSITORY_URL').self::OBJECT_PATH);
320
            $this->assertTrue(is_array($object->getPropertyData()));
321
            $objectUrl = $object->getAbsoluteUrl();
322
            $objectRevision = $object->getRevision();
323
            $object->setTitle($object->getTitle().' (mutated)');
324
            $object->setSlug($object->getSlug().'-mutated');
325
            $object->setDescription($object->getDescription().' (mutated)');
326
            $object->setAbstract($object->getAbstract());
327
            $object->setLicense(ltrim($object->getLicense().', ', ', ').'MIT');
328
            $object->setKeywords(array_merge($object->getKeywords(), ['mutated']));
329
            $object->setCategories($object->getCategories());
330
            $this->assertEquals(preg_replace('%\/(.?+)$%', '/.$1-2', $objectUrl), $object->getAbsoluteUrl());
331
            $this->assertEquals($objectRevision->getRevision() + 1, $object->getRevision()->getRevision());
332
            $this->assertTrue($object->hasBeenModified());
333
            $this->assertTrue($object->hasBeenMutated());
334
            $this->assertEquals('MIT', $object->getLicense());
335
            $this->assertEquals(Object::PRIVACY_PRIVATE, $object->getPrivacy());
336
            $this->assertEquals(Object::PRIVACY_PUBLIC, $object->setPrivacy(Object::PRIVACY_PUBLIC)->getPrivacy());
337
            $object->setPrivacy('invalid');
338
        }
339
340
        /**
341
         * Test mutation by altering domain properties
342
         */
343
        public function testDomainPropertyMutation()
344
        {
345
            $object = Object::instance(getenv('REPOSITORY_URL').self::OBJECT_PATH);
346
            $this->assertTrue(is_array($object->getPropertyData()));
347
            $objectUrl = $object->getAbsoluteUrl();
348
            $objectRevision = $object->getRevision();
349
            $object->setDomainProperty('a:b:c', 'mutated');
350
            $this->assertEquals(preg_replace('%\/(.?+)$%', '/.$1-2', $objectUrl), $object->getAbsoluteUrl());
351
            $this->assertEquals($objectRevision->getRevision() + 1, $object->getRevision()->getRevision());
352
            $this->assertTrue($object->hasBeenModified());
353
            $this->assertTrue($object->hasBeenMutated());
354
        }
355
356
        /**
357
         * Test change by altering processing instructions
358
         */
359
        public function testProcessingInstructionChange()
360
        {
361
            $object = Object::instance(getenv('REPOSITORY_URL').self::OBJECT_PATH);
362
            $this->assertTrue(is_array($object->getPropertyData()));
363
            $objectUrl = $object->getAbsoluteUrl();
364
            $objectRevision = $object->getRevision();
365
            $object->setProcessingInstruction('css', 'other-style.css');
366
            $this->assertEquals($objectUrl, $object->getAbsoluteUrl());
367
            $this->assertEquals($objectRevision->getRevision(), $object->getRevision()->getRevision());
368
            $this->assertTrue($object->hasBeenModified());
369
            $this->assertFalse($object->hasBeenMutated());
370
        }
371
372
        /**
373
         * Test change by altering relations
374
         */
375
        public function testRelationChange()
376
        {
377
            // TODO: Implement
378
        }
379
380
        /**
381
         * Test to persist an earlier revision
382
         */
383
        public function testPersistEarlierRevision()
384
        {
385
            // TODO
386
        }
387
388
        /**
389
         * Test the creation and persisting of an article object with failing file lock
390
         *
391
         * @expectedException \Apparat\Object\Domain\Repository\RuntimeException
392
         * @expectedExceptionCode 1461406873
393
         */
394
        public function testCreateArticleObjectLockingImpossible()
395
        {
396
            putenv('MOCK_FLOCK=1');
397
            $this->testCreateAndPublishArticleObject();
398
        }
399
400
        /**
401
         * Test the creation and persisting of an article object
402
         *
403
         * @expectedException \Apparat\Object\Domain\Model\Object\RuntimeException
404
         * @expectedExceptionCode 1462124874
405
         */
406
        public function testCreateAndPublishArticleObject()
407
        {
408
            // Create a temporary repository & article
409
            $tempRepoDirectory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'temp-repo';
410
            $payload = 'Revision 1 draft';
411
            $article = $this->createRepositoryAndArticleObject($tempRepoDirectory, $payload);
412
            $this->assertInstanceOf(Article::class, $article);
413
            $this->assertEquals($payload, $article->getPayload());
414
            $this->assertFileExists($tempRepoDirectory.
415
                str_replace('/', DIRECTORY_SEPARATOR, $article->getRepositoryPath()
416
                    ->withExtension(getenv('OBJECT_RESOURCE_EXTENSION'))));
417
418
            // Alter and persist the object
419
            $article->setPayload('Revision 1 draft (updated)');
420
            $article->persist();
421
422
            // Publish and persist the first object revision
423
            $article->setPayload('Revision 1');
424
            $article->publish();
425
            $article->persist();
426
427
            // Draft a second object revision
428
            $article->setPayload('Revision 2 draft');
429
            $article->persist();
430
431
            // Publish and persist the second object revision
432
            $article->publish();
433
            $article->setPayload('Revision 2');
434
            $article->persist();
435
436
            // Modify and persist a third object draft revision
437
            $article->setPayload('Revision 3 draft');
438
            $article->persist();
439
440
            // Wait for 2 seconds, modify and re-persist the object
441
            $now = time();
442
            sleep(2);
443
            $article->setPayload('Revision 3 draft (delayed modification)');
444
            $article->persist();
445
            $this->assertGreaterThanOrEqual($now + 2, $article->getModified()->format('U'));
446
447
            // Iterate through all object revisions
448
            foreach ($article as $articleRevisionIndex => $articleRevision) {
449
                $this->assertInstanceOf(Article::class, $articleRevision);
450
                $this->assertInstanceOf(Revision::class, $articleRevisionIndex);
451
            }
452
453
            // Publish and persist a third object draft revision
454
            $article->publish()->persist();
455
456
            // Delete the object (and all it's revisions)
457
            $article->delete()->persist();
458
459
            // Undelete the object (and all it's revisions)
460
            $article->undelete()->persist();
461
462
            // Use the first revision
463
            $article->rewind();
464
465
            // Delete temporary repository
466
            $this->deleteRecursive($tempRepoDirectory);
467
468
            $article->persist();
469
        }
470
471
        /**
472
         * Test the creation and persisting of an article object with failing file lock
473
         *
474
         * @expectedException \Apparat\Object\Infrastructure\Repository\RuntimeException
475
         * @expectedExceptionCode 1464269155
476
         */
477
        public function testDeleteArticleObjectImpossible()
478
        {
479
            putenv('MOCK_RENAME=1');
480
            $this->tmpFiles[] = $tempRepoDirectory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'temp-repo';
481
            $article = $this->createRepositoryAndArticleObject($tempRepoDirectory, 'Revision 1 draft');
482
            $this->deleteRecursive($tempRepoDirectory);
483
            $article->delete()->persist();
484
        }
485
486
        /**
487
         * Test the creation and persisting of an article object with failing file lock
488
         *
489
         * @expectedException \Apparat\Object\Infrastructure\Repository\RuntimeException
490
         * @expectedExceptionCode 1464269179
491
         */
492
        public function testUndeleteArticleObjectImpossible()
493
        {
494
            $this->tmpFiles[] = $tempRepoDirectory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'temp-repo';
495
            $article = $this->createRepositoryAndArticleObject($tempRepoDirectory, 'Revision 1 draft');
496
            $article->getRepositoryPath()->getRepository()->deleteObject($article);
497
            $this->deleteRecursive($tempRepoDirectory);
498
            putenv('MOCK_RENAME=1');
499
            $article->undelete()->persist();
500
        }
501
502
        /**
503
         * Create a temporary repository and article object
504
         *
505
         * @param string $tempRepoDirectory Repository directory
506
         * @param string $payload Article payload
507
         * @return Article Article object
508
         */
509
        protected function createRepositoryAndArticleObject($tempRepoDirectory, $payload)
510
        {
511
            $fileRepository = RepositoryFactory::create(
512
                getenv('REPOSITORY_URL'),
513
                [
514
                    'type' => FileAdapterStrategy::TYPE,
515
                    'root' => $tempRepoDirectory,
516
                ]
517
            );
518
            $this->assertInstanceOf(Repository::class, $fileRepository);
519
            $this->assertEquals($fileRepository->getAdapterStrategy()->getRepositorySize(), 0);
520
521
            // Create a new article in the temporary repository
522
            return $fileRepository->createObject(Type::ARTICLE, $payload);
523
        }
524
525
        /**
526
         * Recursively register a directory and all nested files and directories for deletion on teardown
527
         *
528
         * @param string $directory Directory
529
         */
530
        protected function deleteRecursive($directory)
531
        {
532
            $this->tmpFiles[] = $directory;
533
            foreach (scandir($directory) as $item) {
534
                if (!preg_match('%^\.+$%', $item)) {
535
                    $path = $directory.DIRECTORY_SEPARATOR.$item;
536
                    if (is_dir($path)) {
537
                        $this->deleteRecursive($path);
538
                        continue;
539
                    }
540
541
                    $this->tmpFiles[] = $path;
542
                }
543
            }
544
        }
545
    }
546
}
547
548
namespace Apparat\Object\Infrastructure\Repository {
549
550
    /**
551
     * Mocked version of the native flock() function
552
     *
553
     * @param resource $handle An open file pointer.
554
     * @param int $operation Operation is one of the following: LOCK_SH to acquire a shared lock (reader).
555
     * @param int $wouldblock The optional third argument is set to true if the lock would block (EWOULDBLOCK errno
556
     *     condition).
557
     * @return bool True on success or False on failure.
558
     */
559
    function flock($handle, $operation, &$wouldblock = null)
560
    {
561
        return (getenv('MOCK_FLOCK') != 1) ? \flock($handle, $operation, $wouldblock) : false;
562
    }
563
564
    /**
565
     * Mocked version of the native rename() function
566
     *
567
     * @param string $oldname The old name. The wrapper used in oldname must match the wrapper used in newname.
568
     * @param @param string $newname The new name.
569
     * @return bool true on success or false on failure.
570
     */
571
    function rename($oldname, $newname)
572
    {
573
        return (getenv('MOCK_RENAME') != 1) ? \rename($oldname, $newname) : false;
574
    }
575
}
576