-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug tag that shows the assigned variables.
- Loading branch information
Bauffman
committed
Feb 14, 2012
1 parent
36805db
commit 4bd7bb9
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
<?php | |||
|
|||
/* | |||
* This file is part of Spoon Library. | |||
* | |||
* (c) Davy Hellemans <davy@spoon-library.com> | |||
* | |||
* For the full copyright and license information, please view the license | |||
* file that was distributed with this source code. | |||
*/ | |||
|
|||
namespace Spoon\Template\Parser; | |||
use Spoon\Template\TokenStream; | |||
use Spoon\Template\Environment; | |||
use Spoon\Template\Writer; | |||
|
|||
/** | |||
* Writes the debug node to the writer. | |||
* | |||
* @author Davy Hellemans <davy@spoon-library.com> | |||
*/ | |||
class DebugNode extends Node | |||
{ | |||
/** | |||
* Writes the compiled PHP code to the writer object. | |||
* | |||
* @param Spoon\Template\Writer $writer | |||
*/ | |||
public function compile(Writer $writer) | |||
{ | |||
$writer->write("var_dump(\$context);\n", $this->line); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,65 @@ | |||
<?php | |||
|
|||
/* | |||
* This file is part of Spoon Library. | |||
* | |||
* (c) Davy Hellemans <davy@spoon-library.com> | |||
* | |||
* For the full copyright and license information, please view the license | |||
* file that was distributed with this source code. | |||
*/ | |||
|
|||
namespace Spoon\Template\Tests; | |||
use Spoon\Template\Autoloader; | |||
use Spoon\Template\Writer; | |||
use Spoon\Template\TokenStream; | |||
use Spoon\Template\Token; | |||
use Spoon\Template\Environment; | |||
use Spoon\Template\Parser\DebugNode; | |||
|
|||
require_once realpath(dirname(__FILE__) . '/../') . '/Autoloader.php'; | |||
require_once 'PHPUnit/Framework/TestCase.php'; | |||
|
|||
class DebugNodeTest extends \PHPUnit_Framework_TestCase | |||
{ | |||
/** | |||
* @var Spoon\Template\Parser\DebugNode | |||
*/ | |||
protected $node; | |||
|
|||
/** | |||
* @var Spoon\Template\Writer | |||
*/ | |||
protected $writer; | |||
|
|||
public function setUp() | |||
{ | |||
Autoloader::register(); | |||
$this->writer = new Writer(); | |||
|
|||
// {endif} | |||
$stream = new TokenStream( | |||
array( | |||
new Token(Token::BLOCK_START, null, 1), | |||
new Token(Token::NAME, 'endif', 1), | |||
new Token(Token::BLOCK_END, null, 1) | |||
) | |||
); | |||
$this->node = new DebugNode($stream, new Environment()); | |||
} | |||
|
|||
public function tearDown() | |||
{ | |||
$this->writer = null; | |||
$this->node = null; | |||
} | |||
|
|||
public function testCompile() | |||
{ | |||
$this->node->compile($this->writer); | |||
$this->assertEquals( | |||
"// line 1\nvar_dump(\$context);\n", | |||
$this->writer->getSource() | |||
); | |||
} | |||
} |