From d39c531e8b395c3fac7025d744c514e681b2ffa8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 16 Nov 2012 16:01:24 -0600 Subject: [PATCH 1/3] [zendframework/zf2#2878] Fix regressions - Base formatter was calling a method on itself using self::methodName() notation; changing this to "static" raised an issue, as the method is non-static. - Two tests were essentially testing whether typehinting would correctly prevent non-formatter arguments. These tests were (a) unnecessary, and (b) did not work on all versions of PHP. Removed. --- src/Formatter/Base.php | 2 +- test/Writer/AbstractTest.php | 10 ---------- test/Writer/DbTest.php | 9 --------- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/Formatter/Base.php b/src/Formatter/Base.php index 1b971181..a495dfd3 100644 --- a/src/Formatter/Base.php +++ b/src/Formatter/Base.php @@ -52,7 +52,7 @@ public function format($event) foreach ($event as $key => $value) { // Keep extra as an array if ('extra' === $key) { - $event[$key] = static::format($value); + $event[$key] = self::format($value); } else { $event[$key] = $this->normalize($value); } diff --git a/test/Writer/AbstractTest.php b/test/Writer/AbstractTest.php index 68f9a42b..33983619 100644 --- a/test/Writer/AbstractTest.php +++ b/test/Writer/AbstractTest.php @@ -30,16 +30,6 @@ protected function setUp() $this->_writer = new ConcreteWriter(); } - /** - * @group ZF-6085 - */ - public function testSetFormatter() - { - $this->_writer->setFormatter(new SimpleFormatter()); - $this->setExpectedException('PHPUnit_Framework_Error'); - $this->_writer->setFormatter(new \StdClass()); - } - public function testAddFilter() { $this->_writer->addFilter(1); diff --git a/test/Writer/DbTest.php b/test/Writer/DbTest.php index 8a2467a6..41dca67a 100644 --- a/test/Writer/DbTest.php +++ b/test/Writer/DbTest.php @@ -197,15 +197,6 @@ public function testShutdownRemovesReferenceToDatabaseInstance() $this->writer->write(array('message' => 'this should fail')); } - /** - * @group ZF-10089 - */ - public function testThrowStrictSetFormatter() - { - $this->setExpectedException('PHPUnit_Framework_Error'); - $this->writer->setFormatter(new \StdClass()); - } - public function testWriteDateTimeAsTimestamp() { $date = new DateTime(); From a5b4b8d6770cf6de22a5c9c3313fa8594c71360b Mon Sep 17 00:00:00 2001 From: Alex Denvir Date: Fri, 9 Nov 2012 15:33:33 +0000 Subject: [PATCH 2/3] Improve coding standards on new traits, add tests --- src/LoggerAwareTrait.php | 6 ++--- test/LoggerAwareTraitTest.php | 33 +++++++++++++++++++++++++ test/TestAsset/MockLoggerAwareTrait.php | 19 ++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/LoggerAwareTraitTest.php create mode 100644 test/TestAsset/MockLoggerAwareTrait.php diff --git a/src/LoggerAwareTrait.php b/src/LoggerAwareTrait.php index 02f538df..b610682d 100644 --- a/src/LoggerAwareTrait.php +++ b/src/LoggerAwareTrait.php @@ -19,15 +19,15 @@ trait LoggerAwareTrait { /** - * @var \Zend\Log\LoggerInterface + * @var LoggerInterface */ protected $logger = null; /** * setLogger * - * @param \Zend\Log\LoggerInterface $logger - * @return + * @param LoggerInterface $logger + * @return mixed */ public function setLogger(LoggerInterface $logger) { diff --git a/test/LoggerAwareTraitTest.php b/test/LoggerAwareTraitTest.php new file mode 100644 index 00000000..e981e139 --- /dev/null +++ b/test/LoggerAwareTraitTest.php @@ -0,0 +1,33 @@ +assertAttributeEquals(null, 'logger', $object); + + $logger = new Logger; + + $object->setLogger($logger); + + $this->assertAttributeEquals($logger, 'logger', $object); + } +} diff --git a/test/TestAsset/MockLoggerAwareTrait.php b/test/TestAsset/MockLoggerAwareTrait.php new file mode 100644 index 00000000..4bbac129 --- /dev/null +++ b/test/TestAsset/MockLoggerAwareTrait.php @@ -0,0 +1,19 @@ + Date: Mon, 19 Nov 2012 17:30:14 +0000 Subject: [PATCH 3/3] Improve function comment quality, clean up tests a little --- src/LoggerAwareTrait.php | 2 +- test/LoggerAwareTraitTest.php | 8 ++++---- test/TestAsset/MockLoggerAwareTrait.php | 19 ------------------- 3 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 test/TestAsset/MockLoggerAwareTrait.php diff --git a/src/LoggerAwareTrait.php b/src/LoggerAwareTrait.php index b610682d..33cbfe43 100644 --- a/src/LoggerAwareTrait.php +++ b/src/LoggerAwareTrait.php @@ -24,7 +24,7 @@ trait LoggerAwareTrait protected $logger = null; /** - * setLogger + * Set logger object * * @param LoggerInterface $logger * @return mixed diff --git a/test/LoggerAwareTraitTest.php b/test/LoggerAwareTraitTest.php index e981e139..55e9ad78 100644 --- a/test/LoggerAwareTraitTest.php +++ b/test/LoggerAwareTraitTest.php @@ -13,14 +13,14 @@ use \PHPUnit_Framework_TestCase as TestCase; use \Zend\Log\Logger; +/** + * @requires PHP 5.4 + */ class LoggerAwareTraitTest extends TestCase { - /** - * @requires PHP 5.4 - */ public function testSetLogger() { - $object = new TestAsset\MockLoggerAwareTrait; + $object = $this->getObjectForTrait('\Zend\Log\LoggerAwareTrait'); $this->assertAttributeEquals(null, 'logger', $object); diff --git a/test/TestAsset/MockLoggerAwareTrait.php b/test/TestAsset/MockLoggerAwareTrait.php deleted file mode 100644 index 4bbac129..00000000 --- a/test/TestAsset/MockLoggerAwareTrait.php +++ /dev/null @@ -1,19 +0,0 @@ -