Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Unit testing (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonmedina committed Feb 7, 2015
1 parent 0292420 commit 1180d9a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/NodeVisitors/ErrorSuppressionVisitorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

require_once __DIR__.'/../../vendor/autoload.php';
use edsonmedina\php_testability\NodeVisitors\ErrorSuppressionVisitor;

class ErrorSuppressionVisitorTest extends PHPUnit_Framework_TestCase
{
public function setup ()
{
$this->data = $this->getMockBuilder('edsonmedina\php_testability\ReportData')
->disableOriginalConstructor()
->setMethods(array('addIssue'))
->getMock();

$this->scope = $this->getMockBuilder('edsonmedina\php_testability\AnalyserScope')
->disableOriginalConstructor()
->getMock();

$this->node = $this->getMockBuilder ('PhpParser\Node\Expr\ErrorSuppress')
->disableOriginalConstructor()
->getMock();

$this->node2 = $this->getMockBuilder ('PhpParser\Node\Expr\StaticCall')
->disableOriginalConstructor()
->getMock();

$this->factory = $this->getMockBuilder ('edsonmedina\php_testability\AnalyserAbstractFactory')
->getMock();
}

/**
* @covers edsonmedina\php_testability\NodeVisitors\ErrorSuppressionVisitor::leaveNode
*/
public function testLeaveNodeWithDifferentType ()
{
$this->data->expects($this->never())->method('addIssue');

$visitor = new ErrorSuppressionVisitor ($this->data, $this->scope, $this->factory);
$visitor->leaveNode ($this->node2);
}

/**
* @covers edsonmedina\php_testability\NodeVisitors\ErrorSuppressionVisitor::leaveNode
*/
public function testLeaveNodeInGlobalSpace ()
{
$this->data->expects($this->never())->method('addIssue');

$this->scope->method ('inGlobalSpace')->willReturn (true);

$visitor = new ErrorSuppressionVisitor ($this->data, $this->scope, $this->factory);
$visitor->leaveNode ($this->node);
}

/**
* @covers edsonmedina\php_testability\NodeVisitors\ErrorSuppressionVisitor::leaveNode
*/
public function testLeaveNode ()
{
$this->data->expects($this->once())->method('addIssue');

$this->scope->method ('inGlobalSpace')->willReturn (false);

$visitor = new ErrorSuppressionVisitor ($this->data, $this->scope, $this->factory);
$visitor->leaveNode ($this->node);
}
}
13 changes: 13 additions & 0 deletions tests/NodeVisitors/GlobalVarVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ public function testLeaveNodeInGlobalSpace ()
$visitor = new GlobalVarVisitor ($this->data, $this->scope, $this->factory);
$visitor->leaveNode ($this->node);
}

/**
* @covers edsonmedina\php_testability\NodeVisitors\GlobalVarVisitor::leaveNode
*/
public function testLeaveNode ()
{
$this->data->expects($this->once())->method('addIssue');

$this->scope->method ('inGlobalSpace')->willReturn (false);

$visitor = new GlobalVarVisitor ($this->data, $this->scope, $this->factory);
$visitor->leaveNode ($this->node);
}
}
20 changes: 20 additions & 0 deletions tests/NodeVisitors/StaticPropertyFetchVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,29 @@ public function testLeaveNodeFetchingFromSelf()
*/
public function testIsFetchingFromSelfOutsideOfClass()
{
$this->data->expects($this->never())->method('addIssue');

$this->scope->method ('insideClass')->willReturn (false);

$visitor = new StaticPropertyFetchVisitor ($this->data, $this->scope, $this->factory);
$this->assertFalse ($visitor->isFetchingFromSelf ($this->node));
}

/**
* @covers edsonmedina\php_testability\NodeVisitors\StaticPropertyFetchVisitor::leaveNode
*/
public function testLeaveNode()
{
$this->data->expects($this->once())->method('addIssue');

// visitor
$visitor = $this->getMockBuilder ('edsonmedina\php_testability\NodeVisitors\StaticPropertyFetchVisitor')
->setConstructorArgs(array($this->data, $this->scope, $this->factory))
->setMethods (array('isFetchingFromSelf'))
->getMock();

$visitor->method ('isFetchingFromSelf')->willReturn (false);

$visitor->leaveNode ($this->node);
}
}

0 comments on commit 1180d9a

Please sign in to comment.