annotate vendor/psy/psysh/test/Psy/Test/CodeCleaner/NamespacePassTest.php @ 8:50b0d041100e

Further files for download
author Chris Cannam
date Mon, 05 Feb 2018 10:56:40 +0000
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of Psy Shell.
Chris@0 5 *
Chris@0 6 * (c) 2012-2017 Justin Hileman
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Psy\Test\CodeCleaner;
Chris@0 13
Chris@0 14 use Psy\CodeCleaner;
Chris@0 15 use Psy\CodeCleaner\NamespacePass;
Chris@0 16
Chris@0 17 class NamespacePassTest extends CodeCleanerTestCase
Chris@0 18 {
Chris@0 19 private $cleaner;
Chris@0 20
Chris@0 21 public function setUp()
Chris@0 22 {
Chris@0 23 $this->cleaner = new CodeCleaner();
Chris@0 24 $this->setPass(new NamespacePass($this->cleaner));
Chris@0 25 }
Chris@0 26
Chris@0 27 public function testProcess()
Chris@0 28 {
Chris@0 29 $this->process('array_merge()');
Chris@0 30 $this->assertNull($this->cleaner->getNamespace());
Chris@0 31
Chris@0 32 // A non-block namespace statement should set the current namespace.
Chris@0 33 $this->process('namespace Alpha');
Chris@0 34 $this->assertEquals(array('Alpha'), $this->cleaner->getNamespace());
Chris@0 35
Chris@0 36 // A new non-block namespace statement should override the current namespace.
Chris@0 37 $this->process('namespace Beta; class B {}');
Chris@0 38 $this->assertEquals(array('Beta'), $this->cleaner->getNamespace());
Chris@0 39
Chris@0 40 // @todo Figure out if we can detect when the last namespace block is
Chris@0 41 // bracketed or unbracketed, because this should really clear the
Chris@0 42 // namespace at the end...
Chris@0 43 $this->process('namespace Gamma { array_merge(); }');
Chris@0 44 $this->assertEquals(array('Gamma'), $this->cleaner->getNamespace());
Chris@0 45
Chris@0 46 // A null namespace clears out the current namespace.
Chris@0 47 $this->process('namespace { array_merge(); }');
Chris@0 48 $this->assertNull($this->cleaner->getNamespace());
Chris@0 49 }
Chris@0 50
Chris@0 51 private function process($code)
Chris@0 52 {
Chris@0 53 $stmts = $this->parse($code);
Chris@0 54 $this->traverse($stmts);
Chris@0 55 }
Chris@0 56 }