-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed RichTextTest so that tests fails if unexpected logs messages ar…
…e created
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
tests/lib/FieldType/Converter/MethodCallCountConstraint.php
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,91 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Platform XmlText Field Type package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\EzPlatformXmlTextFieldType\Tests\FieldType\Converter; | ||
|
||
use PHPUnit_Framework_MockObject_Invocation; | ||
use PHPUnit_Framework_MockObject_Matcher_InvokedRecorder; | ||
use PHPUnit_Framework_ExpectationFailedException; | ||
|
||
/** | ||
* Class MethodCallCountConstraint. | ||
* | ||
* When generating mocks in PHPUnit, you cannot validate that the mock methods are called the correct | ||
* number of times. | ||
* | ||
* However, with this constrain you may. | ||
* To ensure foobarMethod() is not called more than twice: | ||
* $mock->expects(new MethodCallCountConstraint(2))->method('foobarMethod); | ||
* | ||
* Based on workaround proposed on https://github.com/sebastianbergmann/phpunit-mock-objects/issues/65 | ||
*/ | ||
class MethodCallCountConstraint extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $expectedCount; | ||
|
||
/** | ||
* @param int $expectedCount | ||
*/ | ||
public function __construct($expectedCount) | ||
{ | ||
$this->expectedCount = $expectedCount; | ||
} | ||
|
||
/** | ||
* @param PHPUnit_Framework_MockObject_Invocation $invocation | ||
* @return mixed|void | ||
* @throws PHPUnit_Framework_ExpectationFailedException | ||
*/ | ||
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) | ||
{ | ||
parent::invoked($invocation); | ||
|
||
$count = $this->getInvocationCount(); | ||
|
||
if ($count > $this->expectedCount) { | ||
$message = 'Call to ' . $invocation->toString() . ' unexpected'; | ||
|
||
throw new PHPUnit_Framework_ExpectationFailedException($message); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a string representation of the object. | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'MethodCallCountConstraint'; | ||
} | ||
|
||
/** | ||
* Verifies that the current expectation is valid. If everything is OK the | ||
* code should just return, if not it must throw an exception. | ||
* | ||
* @throws PHPUnit_Framework_ExpectationFailedException | ||
*/ | ||
public function verify() | ||
{ | ||
$count = $this->getInvocationCount(); | ||
if ($count != $this->expectedCount) { | ||
throw new PHPUnit_Framework_ExpectationFailedException( | ||
sprintf( | ||
'Methods of class was expected to be called %d times, ' . | ||
'actually called %d times.', | ||
|
||
$this->expectedCount, | ||
$count | ||
) | ||
); | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
tests/lib/FieldType/Converter/_fixtures/richtext/log/002-dupid-embed.log
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
warning:Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : myembed_id --> duplicated_id_myembed_id_idm* | ||
warning:Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : myembed_id --> duplicated_id_myembed_id_idm* |
1 change: 1 addition & 0 deletions
1
tests/lib/FieldType/Converter/_fixtures/richtext/log/003-dupid-anchor.log
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
warning:Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : anchor --> duplicated_id_anchor_idm* | ||
warning:Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : anchor --> duplicated_id_anchor_idm* |
1 change: 1 addition & 0 deletions
1
tests/lib/FieldType/Converter/_fixtures/richtext/log/081-header-with-embed.log
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
notice:Found embed(s) inside header tag. Embed(s) where moved outside header where contentobject_attribute.id= | ||
notice:Found embed(s) inside header tag. Embed(s) where moved outside header where contentobject_attribute.id= |