Browse Source

Merge pull request #565 from holtkamp/patch-early-suppress-file-not-found-warnings

Allow early suppressing of file not found warnings in Zend_Application
Frank Brückner 10 years ago
parent
commit
712b7ec2f4
2 changed files with 30 additions and 1 deletions
  1. 3 1
      library/Zend/Application.php
  2. 27 0
      tests/Zend/Application/ApplicationTest.php

+ 3 - 1
library/Zend/Application.php

@@ -70,15 +70,17 @@ class Zend_Application
      *
      * @param  string                   $environment
      * @param  string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
+     * @param bool $suppressNotFoundWarnings Should warnings be suppressed when a file is not found during autoloading?
      * @throws Zend_Application_Exception When invalid options are provided
      * @return void
      */
-    public function __construct($environment, $options = null)
+    public function __construct($environment, $options = null, $suppressNotFoundWarnings = null)
     {
         $this->_environment = (string) $environment;
 
         require_once 'Zend/Loader/Autoloader.php';
         $this->_autoloader = Zend_Loader_Autoloader::getInstance();
+        $this->_autoloader->suppressNotFoundWarnings($suppressNotFoundWarnings);
 
         if (null !== $options) {
             if (is_string($options)) {

+ 27 - 0
tests/Zend/Application/ApplicationTest.php

@@ -108,6 +108,33 @@ class Zend_Application_ApplicationTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($options, $application->getOptions());
     }
 
+    /**
+     * @group GH-564
+     * @depends testConstructorInstantiatesAutoloader
+     */
+    public function testConstructorRespectsSuppressFileNotFoundWarningFlag()
+    {
+        $application = new Zend_Application('testing');
+        $this->assertFalse($application->getAutoloader()->suppressNotFoundWarnings()); //Default value
+
+        $application = new Zend_Application('testing', null, $suppressNotFoundWarnings = true);
+        $this->assertTrue($application->getAutoloader()->suppressNotFoundWarnings());
+
+        $application = new Zend_Application('testing', null, $suppressNotFoundWarnings = false);
+        $this->assertFalse($application->getAutoloader()->suppressNotFoundWarnings());
+
+        $options = array(
+            'foo' => 'bar',
+            'bar' => 'baz',
+        );
+
+        $application = new Zend_Application('testing', $options, $suppressNotFoundWarnings = true);
+        $this->assertTrue($application->getAutoloader()->suppressNotFoundWarnings());
+
+        $application = new Zend_Application('testing', $options, $suppressNotFoundWarnings = false);
+        $this->assertFalse($application->getAutoloader()->suppressNotFoundWarnings());
+    }
+
     public function testHasOptionShouldReturnFalseWhenOptionNotPresent()
     {
         $this->assertFalse($this->application->hasOption('foo'));