Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/7263'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Mar 25, 2015
148 parents c7f8b7f + e709e4d + b652dfb + db2794e + 6fca41f + 317429f + 6753576 + 4112f92 + 6faf2bb + df3a849 + ee5efcb + 2ee5d16 + bcb4d03 + a5c61e2 + 57ffceb + a6fa26b + 9d36595 + bf0040c + 71b1a95 + 5619ba3 + c093ab0 + de13946 + 04b025f + 0933607 + 34ed3ed + 83f6472 + db74e8c + 7b75da1 + bb4c48f + 9fa3c05 + 139c0b1 + a587eef + 7a782f4 + 39cb2e2 + 31f8c80 + a9b7779 + de058f6 + 67b97f6 + 40d86d0 + b5234cc + 17b4e13 + 8af24aa + 1a9df55 + 2c85c99 + 5557fac + fe78a35 + f6430c3 + 6041a1e + 86b9031 + 674bd75 + 67a1bfb + 4d4dd8b + c655082 + dbb18b2 + 97a9134 + 80367df + 98d5255 + 7946c9f + ea67c13 + 44df0b2 + 38e090d + 7af74e7 + 8b311b1 + e2c2b94 + 51601cb + dcc1eaf + 6f4b805 + a30a64f + ee7347d + 8b04bfe + b487f00 + ecdfdf6 + d8cde75 + b7a33bb + 65ecb58 + 571d938 + 625a786 + 6fe4efc + f94838d + 76607e3 + 492076c + 17b56b8 + c5509fe + e0fa433 + 7d74e99 + 309136e + f1dd38a + 7be533f + 6a618c2 + 3a454e3 + f66ca80 + f1bebf2 + 850249d + 674d7ba + 597ff82 + ae87c49 + fb156fb + 9c474de + 1a75c72 + 47d1cd2 + a937ea3 + 4219922 + 49e380f + 5903df6 + 7a9d632 + 2ef7274 + b606220 + a09c5c7 + 21afa5c + 8faa67f + 1731915 + efa1bb3 + 5576455 + 86d3ae8 + de3fd70 + 398a3c4 + 5c56554 + 7ad896f + fa91c9b + 1372a45 + a0c8737 + e368d53 + 462b1f7 + 79675fe + a8104b9 + 91ed9d0 + b1d1358 + 6a0c90c + 5e4258f + 239c0d0 + b457c76 + a2533a4 + beb6598 + 79d0f46 + 1519723 + 5084e3b + ce75f80 + e5fd689 + 6744e82 + 6cb64b8 + 03c6da8 + 7dcfd8f + a18fe5d + 5e5ada1 + 439fdac + e6addba + 5422681 + e5d5a37 commit 64f974b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 22 deletions.
23 changes: 23 additions & 0 deletions src/Writer/Noop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Log\Writer;

class Noop extends AbstractWriter
{
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
protected function doWrite(array $event)
{
}
}
28 changes: 20 additions & 8 deletions src/Writer/Null.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@

namespace Zend\Log\Writer;

class Null extends AbstractWriter
/**
* Stub class for backwards compatibility.
*
* Since PHP 7 adds "null" as a reserved keyword, we can no longer have a class
* named that and retain PHP 7 compatibility. The original class has been
* renamed to "Noop", and this class is now an extension of it. It raises an
* E_USER_DEPRECATED to warn users to migrate.
*
* @deprecated
*/
class Null extends Noop
{
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
protected function doWrite(array $event)
public function __construct()
{
trigger_error(
sprintf(
'The class %s has been deprecated; please use %s\\Noop',
__CLASS__,
__NAMESPACE__
),
E_USER_DEPRECATED
);
}
}
7 changes: 6 additions & 1 deletion src/WriterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class WriterPluginManager extends AbstractPluginManager
{
protected $aliases = array(
'null' => 'noop',
'Zend\Log\Writer\Null' => 'noop',
);

/**
* Default set of writers
*
Expand All @@ -25,7 +30,7 @@ class WriterPluginManager extends AbstractPluginManager
'firephp' => 'Zend\Log\Writer\FirePhp',
'mail' => 'Zend\Log\Writer\Mail',
'mock' => 'Zend\Log\Writer\Mock',
'null' => 'Zend\Log\Writer\Null',
'noop' => 'Zend\Log\Writer\Noop',
'stream' => 'Zend\Log\Writer\Stream',
'syslog' => 'Zend\Log\Writer\Syslog',
'zendmonitor' => 'Zend\Log\Writer\ZendMonitor',
Expand Down
31 changes: 21 additions & 10 deletions test/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testSetWriters()
$writers = $this->logger->getWriters();
$this->assertInstanceOf('Zend\Stdlib\SplPriorityQueue', $writers);
$writer = $writers->extract();
$this->assertTrue($writer instanceof \Zend\Log\Writer\Null);
$this->assertTrue($writer instanceof \Zend\Log\Writer\Noop);
$writer = $writers->extract();
$this->assertTrue($writer instanceof \Zend\Log\Writer\Mock);
}
Expand All @@ -120,7 +120,7 @@ public function testAddWriterWithPriority()

$this->assertInstanceOf('Zend\Stdlib\SplPriorityQueue', $writers);
$writer = $writers->extract();
$this->assertTrue($writer instanceof \Zend\Log\Writer\Null);
$this->assertTrue($writer instanceof \Zend\Log\Writer\Noop);
$writer = $writers->extract();
$this->assertTrue($writer instanceof \Zend\Log\Writer\Mock);
}
Expand All @@ -137,7 +137,7 @@ public function testAddWithSamePriority()
$writer = $writers->extract();
$this->assertTrue($writer instanceof \Zend\Log\Writer\Mock);
$writer = $writers->extract();
$this->assertTrue($writer instanceof \Zend\Log\Writer\Null);
$this->assertTrue($writer instanceof \Zend\Log\Writer\Noop);
}

public function testLogging()
Expand Down Expand Up @@ -369,7 +369,8 @@ public function testExceptionHandler()
$this->assertFalse(Logger::registerExceptionHandler($this->logger));

// get the internal exception handler
$exceptionHandler = set_exception_handler(function ($e) {});
$exceptionHandler = set_exception_handler(function ($e) {
});
set_exception_handler($exceptionHandler);

// reset the exception handler
Expand Down Expand Up @@ -443,6 +444,10 @@ public function testErrorHandlerWithStreamWriter()
*/
public function testRegisterFatalShutdownFunction()
{
if (version_compare(PHP_VERSION, '7', 'ge')) {
$this->markTestSkipped('PHP7: cannot test as code now raises E_ERROR');
}

$writer = new MockWriter;
$this->logger->addWriter($writer);

Expand All @@ -453,14 +458,14 @@ public function testRegisterFatalShutdownFunction()
$this->assertFalse(Logger::registerFatalErrorShutdownFunction($this->logger));

$self = $this;
register_shutdown_function(function () use ($writer, $self) {
register_shutdown_function(function () use ($writer, $self, &$caught) {
$self->assertEquals(
'Call to undefined method ZendTest\Log\LoggerTest::callToNonExistingMethod()',
$writer->events[0]['message']
);
});

// Temporary hide errors, because we don't want the fatal error to fail the test
// Temporarily hide errors, because we don't want the fatal error to fail the test
@$this->callToNonExistingMethod();
}

Expand All @@ -471,6 +476,10 @@ public function testRegisterFatalShutdownFunction()
*/
public function testRegisterFatalErrorShutdownFunctionHandlesCompileTimeErrors()
{
if (version_compare(PHP_VERSION, '7', 'ge')) {
$this->markTestSkipped('PHP7: cannot test as code now raises E_ERROR');
}

$writer = new MockWriter;
$this->logger->addWriter($writer);

Expand All @@ -481,14 +490,14 @@ public function testRegisterFatalErrorShutdownFunctionHandlesCompileTimeErrors()
$this->assertFalse(Logger::registerFatalErrorShutdownFunction($this->logger));

$self = $this;
register_shutdown_function(function () use ($writer, $self) {
register_shutdown_function(function () use ($writer, $self, &$caught) {
$self->assertStringMatchesFormat(
'syntax error%A',
$writer->events[0]['message']
);
});

// Temporary hide errors, because we don't want the fatal error to fail the test
// Temporarily hide errors, because we don't want the fatal error to fail the test
@eval('this::code::is::invalid {}');
}

Expand All @@ -497,8 +506,10 @@ public function testRegisterFatalErrorShutdownFunctionHandlesCompileTimeErrors()
*/
public function testCatchExceptionNotValidPriority()
{
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException',
'$priority must be an integer >= 0 and < 8; received -1');
$this->setExpectedException(
'Zend\Log\Exception\InvalidArgumentException',
'$priority must be an integer >= 0 and < 8; received -1'
);
$writer = new MockWriter();
$this->logger->addWriter($writer);
$this->logger->log(-1, 'Foo');
Expand Down
24 changes: 24 additions & 0 deletions test/Writer/NoopTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Log\Writer;

use Zend\Log\Writer\Noop as NoopWriter;

/**
* @group Zend_Log
*/
class NoopTest extends \PHPUnit_Framework_TestCase
{
public function testWrite()
{
$writer = new NoopWriter();
$writer->write(array('message' => 'foo', 'priority' => 42));
}
}
13 changes: 10 additions & 3 deletions test/Writer/NullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
*/
class NullTest extends \PHPUnit_Framework_TestCase
{
public function testWrite()
public function setUp()
{
$writer = new NullWriter();
$writer->write(array('message' => 'foo', 'priority' => 42));
if (version_compare(PHP_VERSION, '7.0', '>=')) {
$this->markTestSkipped('Cannot test Null log writer under PHP 7; reserved keyword');
}
}

public function testRaisesNoticeOnInstantiation()
{
$this->setExpectedException('PHPUnit_Framework_Error_Deprecated');
new NullWriter();
}
}

0 comments on commit 64f974b

Please sign in to comment.