فهرست منبع

ZF-7028: better bootstrap detection

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16290 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 سال پیش
والد
کامیت
87757e6a30

+ 7 - 0
library/Zend/Application.php

@@ -288,8 +288,15 @@ class Zend_Application
 
         if (!class_exists($class, false)) {
             require_once $path;
+            if (!class_exists($class, false)) {
+                throw new Zend_Application_Exception('Bootstrap class not found');
+            }
         }
         $this->_bootstrap = new $class($this);
+
+        if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) {
+            throw new Zend_Application_Exception('Bootstrap class does not implement Zend_Application_Bootstrap_Bootstrapper');
+        }
         
         return $this;
     }

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

@@ -328,6 +328,34 @@ class Zend_Application_ApplicationTest extends PHPUnit_Framework_TestCase
         $application = $this->application->bootstrap();
         $this->assertSame($application, $this->application);
     }
+
+    /**
+     * @expectedException Zend_Application_Exception
+     */
+    public function testApplicationShouldRaiseExceptionIfBootstrapFileDoesNotContainBootstrapClass()
+    {
+        $this->application->setOptions(array(
+            'bootstrap' => array(
+                'path'  => dirname(__FILE__) . '/_files/ZfAppNoBootstrap.php',
+                'class' => 'ZfAppNoBootstrap',
+            ),
+        ));
+        $bootstrap = $this->application->getBootstrap();
+    }
+
+    /**
+     * @expectedException Zend_Application_Exception
+     */
+    public function testApplicationShouldRaiseExceptionWhenBootstrapClassNotOfCorrectType()
+    {
+        $this->application->setOptions(array(
+            'bootstrap' => array(
+                'path'  => dirname(__FILE__) . '/_files/ZfAppBadBootstrap.php',
+                'class' => 'ZfAppBadBootstrap',
+            ),
+        ));
+        $bootstrap = $this->application->getBootstrap();
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_ApplicationTest::main') {

+ 4 - 0
tests/Zend/Application/_files/ZfAppBadBootstrap.php

@@ -0,0 +1,4 @@
+<?php
+class ZfAppBadBootstrap
+{
+}

+ 2 - 0
tests/Zend/Application/_files/ZfAppNoBootstrap.php

@@ -0,0 +1,2 @@
+<?php
+// no content