This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Extraction the ExceptionPresenter and renamed StringPresenter to ValuePresenter #100
Open
liuggio
wants to merge
2
commits into
phpspec:develop
Choose a base branch
from
liuggio:feature/PresenterRefactor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace spec\PHPSpec2\Formatter\Presenter; | ||
|
||
use PHPSpec2\ObjectBehavior; | ||
use PHPSpec2\Exception\Example\NotEqualException; | ||
use PHPSpec2\Exception\Exception; | ||
use PHPSpec2\Exception\Example\MockerException; | ||
|
||
class ExceptionPresenter extends ObjectBehavior | ||
{ | ||
/** | ||
* @param PHPSpec2\Formatter\Presenter\ValuePresenter $valuePresenter | ||
* @param PHPSpec2\Formatter\Presenter\Differ\Differ $differ | ||
*/ | ||
function let($valuePresenter, $differ) | ||
{ | ||
$this->beConstructedWith($valuePresenter, $differ); | ||
} | ||
|
||
function it_should_show_the_stacktrace_of_an_exception($valuePresenter) | ||
{ | ||
$exc = new Exception('personal Exception'); | ||
$valuePresenter->presentValue->willReturn('personal Exception'); | ||
$valuePresenter->presentValue->willReturn('"stacktrace"'); | ||
|
||
$this->presentExceptionStackTrace($exc)->shouldBeLike(' | ||
0 spec/PHPSpec2/Formatter/Presenter/ExceptionPresenter.php:23 | ||
throw new PHPSpec2\Exception\Exception(personal Exception) | ||
1 [internal] | ||
spec\PHPSpec2\Formatter\Presenter\ExceptionPresenter->it_should_show_the_stacktrace_of_an_exception("stacktrace") | ||
'); | ||
} | ||
|
||
function it_should_return_a_string_for_different_kind_of_exception($valuePresenter, $mockerException) | ||
{ | ||
throw new \PHPSpec2\Exception\Example\PendingException('Error here, "PHP Fatal error: Call to undefined method Mockery\Exception::setCause() in Formatter/PrettyFormatter.php on line 129"'); | ||
$mockerException->beAMockOf('\PHPSpec2\Exception\Example\MockerException'); | ||
$mockerException->beConstructedWith('Message'); | ||
|
||
$mockerException->setCause('a'); | ||
$mockerException->getCode->willReturn(array()); | ||
$mockerException->getTrace->willReturn(array()); | ||
$mockerException->getFile->willReturn('filename'); | ||
$mockerException->getLine->willReturn(23); | ||
|
||
$valuePresenter->presentValue->willReturn($mockerException); | ||
$this->presentException($mockerException, false)->shuldReturn('AA'); | ||
} | ||
|
||
function it_should_compare_the_exception_with_diff($differ) | ||
{ | ||
$actual = new Exception(); | ||
$expected = new Exception(); | ||
|
||
$notEqualException = new NotEqualException('message', $actual, $expected); | ||
|
||
$differ->compare($actual, $expected)->shouldBeCalled(); | ||
$this->presentExceptionDifference($notEqualException)->shouldReturn(null); | ||
} | ||
|
||
|
||
function it_should_show_the_trace_function($valuePresenter) | ||
{ | ||
$valuePresenter->presentValue->willReturn('2'); | ||
$this->presentExceptionTraceFunction('function', array('2'))->shouldBeLike(" function(2)\n"); | ||
} | ||
|
||
|
||
function it_should_show_the_trace_method($valuePresenter) | ||
{ | ||
$valuePresenter->presentValue->willReturn('3'); | ||
$this->presentExceptionTraceMethod('class', 'type', 'method', array('3'))->shouldBeLike(" classtypemethod(3)\n"); | ||
} | ||
|
||
|
||
|
||
|
||
} |
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
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
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
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
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace PHPSpec2\Exception; | ||
|
||
Interface ExceptionInterface | ||
{ | ||
public function getCause(); | ||
public function setCause($cause); | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace PHPSpec2\Formatter\Presenter\Differ; | ||
|
||
class ArrayEngine implements EngineInterface | ||
{ | ||
public function supports($expected, $actual) | ||
{ | ||
return is_array($expected) && is_array($actual); | ||
} | ||
|
||
public function compare($expected, $actual) | ||
{ | ||
$diff = new \Diff($expected, $actual, array()); | ||
|
||
$renderer = new \Diff_Renderer_Text_Unified; | ||
$text = $diff->render($renderer); | ||
|
||
$lines = array(); | ||
foreach (explode("\n", $text) as $line) { | ||
if (0 === strpos($line, '-')) { | ||
$lines[] = sprintf('<diff-del>%s</diff-del>', $line); | ||
} elseif (0 === strpos($line, '+')) { | ||
$lines[] = sprintf('<diff-add>%s</diff-add>', $line); | ||
} else { | ||
$lines[] = $line; | ||
} | ||
} | ||
|
||
return sprintf("<code>\n%s</code>", implode("\n", $lines)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got some trouble here, a suggestion is very appreciated.