{"id":211328,"date":"2014-02-04T11:09:03","date_gmt":"2014-02-04T07:09:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=211328"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=211328","title":{"rendered":"<span class=\"post_title\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 Dependency Injection<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043e Dependency Injection \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0434\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 PHP-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435. \u0414\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043e PHP.<\/p>\n<p>  \u0414\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434?<\/p>\n<pre><code class=\"php\">class Car {     protected $engine;       public function __construct() {         $this-&gt;engine = new Engine();     }      public function start() {         if ($this-&gt;engine-&gt;hasFuel()) {             $this-&gt;engine-&gt;start();         } else {             throw new CarException(self::EXCEPTION_NO_FUEL);         }     } } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 start \u0438, \u0441\u043a\u0430\u0436\u0435\u043c, \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u043e\u043f\u043b\u0438\u0432\u0430 \u0438 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f? \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 Engine \u0438 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 hasFuel, \u0430 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u201c\u0437\u0430\u0448\u0438\u0442\u201d \u0432 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<a name=\"habracut\"><\/a><\/p>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dependency_injection\">Dependency Injection<\/a>. \u0425\u043e\u0440\u043e\u0448\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<p>  <b>1.<\/b> \u0411\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c.<\/p>\n<pre><code class=\"php\">public function __construct(Engine $engine) {     $this-&gt;engine = $engine; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441 \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/phpunit.de\/\">phpUnit<\/a> \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438, \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <a href=\"http:\/\/phpunit.de\/manual\/3.7\/en\/test-doubles.html\">mock<\/a> \u043a\u043b\u0430\u0441\u0441\u0430 Engine.<\/p>\n<pre><code class=\"php\">class Test extends BaseTest {     public function testStartException() {         $engineMock = $this-&gt;getMock('Engine');         $engineMock-&gt;expects($this-&gt;once())             -&gt;method('hasFuel')             -&gt;will($this-&gt;returnValue(false));         $car = new Car($engineMock);                 $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  <b>2.<\/b> \u0418\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c? \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0430\u0432\u0442\u043e \u0441 \u0433\u0438\u0431\u0440\u0438\u0434\u043d\u044b\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<pre><code class=\"php\">public function start() {     \/\/ hybrid engine can work using electricity or benzin     if (!$this-&gt;battery-&gt;isEmpty() || $this-&gt;engine-&gt;hasFuel()) {         $this-&gt;engine-&gt;start();     } else {         throw new CarException(self::EXCEPTION_NO_ELECTRICITY_OR_FUEL);     } } <\/code><\/pre>\n<p>  \u041c\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u044f\u0442\u044c \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435? \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f <a href=\"http:\/\/en.wikipedia.org\/wiki\/Mutator_method\">setter-\u043c\u0435\u0442\u043e\u0434\u044b<\/a>:<\/p>\n<pre><code class=\"php\">public function setEngine(Engine $engine) {     $this-&gt;engine = $engine; }  public function setBattery(Battery $battery) {     $this-&gt;battery = $battery; } <\/code><\/pre>\n<p>  \u0422\u043e\u0433\u0434\u0430 \u0432 \u0442\u0435\u0441\u0442\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439 mock:<\/p>\n<pre><code class=\"php\">class Test extends BaseTest {     public function testStartException() {         $engineMock = $this-&gt;getMock('Engine');         $engineMock-&gt;expects($this-&gt;once())             -&gt;method('hasFuel')             -&gt;will($this-&gt;returnValue(false));         $batteryMock = $this-&gt;getMock(\u2018Battery\u2019);         $batteryMock-&gt;expects($this-&gt;once())             -&gt;method('isEmpty')             -&gt;will($this-&gt;returnValue(true));                  $car = new Car;         $car-&gt;setEngine($engineMock);         $car-&gt;setBattery($batteryMock);         $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  <b>3.<\/b> \u041c\u0435\u0442\u043e\u0434 \u0432\u044b\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e\u2026 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0442\u043e \u0432\u0430\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u043d\u0430\u0434\u043e\u0435\u0441\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 mocks. \u0422\u0435\u0441\u0442\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438, \u0438 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443, \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0438\u0445 \u0443\u0436\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043e \u0446\u0435\u043b\u044b\u0445 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0442\u0438\u043f\u0430:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 DependencyContainer<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">final class DependencyContainer {      const EXCEPTION_NO_CLASS_NAME = 'There is no such class name: %s';     const EXCEPTION_INVALID_CONFIG = 'Config file is invalid: %s';     const CONFIG_PATH = '\/..\/Config\/dependencyContainer.php';      \/**      * @var DependencyContainer      *\/     private static $instance;     private $config = array();      private final function __construct($configPath) {         $this-&gt;loadConfig($configPath);     }      private final function __clone() {}      \/**      * @return DependencyContainer      *\/     public static function getInstance() {         if (null === self::$instance) {             self::$instance = new self(self::CONFIG_PATH);         }         return self::$instance;     }      private function loadConfig($configPath) {         $config = require __DIR__ . $configPath;         if (!is_array($config)) {             throw new \\InvalidArgumentException(sprintf(self::EXCEPTION_INVALID_CONFIG, $configPath));         }         $this-&gt;config = $config;     }      public function set($className, $fullPath) {         $this-&gt;config[$className] = $fullPath;     }      public function __call($name, $arguments) {         $className = substr($name, strlen('new'));         if (isset($this-&gt;config[$className])) {             return new $this-&gt;config[$className]($arguments);         }         throw new \\InvalidArgumentException(sprintf(self::EXCEPTION_NO_CLASS_NAME, $className));     } } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0421 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u043e\u043c \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php return array(     'Engine' =&gt; '\\App\\Engine',     'Battery' =&gt; '\\App\\Battery', ); <\/code><\/pre>\n<p>  \u0410 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">class Car {     public function __construct() {         $container = DependencyContainer::getInstance();         $this-&gt;engine = $container-&gt;newEngine();         $this-&gt;battery = $container-&gt;newBattery();     } } <\/code><\/pre>\n<p>  \u0422\u043e\u0433\u0434\u0430 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u043e\u0439\u043d\u0438\u043a\u043e\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<pre><code class=\"php\">namespace Tests\\Mocks;  use App;  class Engine extends App\\Engine {     public function hasFuel() {         return false;     } } <\/code><\/pre>\n<p>  \u0410 \u0441\u0430\u043c \u0442\u0435\u0441\u0442 \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043f\u043e\u0434\u043c\u0435\u043d\u0443 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"php\">class Test extends BaseTest {     public function testStartException() {         $container = DependencyContainer::getInstance();         $container-&gt;set('Engine', 'Tests\\Mocks\\Engine');         $container-&gt;set('Battery', 'Tests\\Mocks\\Battery');         $car = new Car;         $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  <b>4.<\/b> \u2026 \u041d\u043e \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 DI Container, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0437\u0430 \u0432\u0430\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u043a\u043e\u043d\u0444\u0438\u0433, \u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u044c\u043c\u0435\u043c <a href=\"http:\/\/symfony.com\/doc\/current\/components\/dependency_injection\/introduction.html\">Symphony DependencyInjection<\/a>. \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <a href=\"https:\/\/packagist.org\/packages\/symfony\/dependency-injection\">\u0447\u0435\u0440\u0435\u0437 Composer<\/a>, \u0438 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0440\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"php\">namespace Tests;  use Symfony\\Component\\DependencyInjection\\ContainerBuilder;  class Test extends BaseTest {     public function testStartException() {         $container = new ContainerBuilder;         $container             -&gt;register('car', '\\App\\Car')             -&gt;addMethodCall('setEngine', array(new Mocks\\Engine))             -&gt;addMethodCall('setBattery', array(new Mocks\\Battery));         $car = $container-&gt;get('car');         $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u044b\u0448\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0445 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0438 \u0432 \u0432\u0438\u0434\u0435 XML\/YAML\/PHP, \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u043e\u043f\u0440\u043e\u0441: \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0438\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043d\u0441\u0442\u0440\u0443\u043e\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0432 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445\u2026<\/p>\n<p>  <b>5.<\/b> \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u043c\u044b\u0441\u043b\u044c \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c DI \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u043a\u0443\u0434\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b. \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043e \u0441\u043c\u044b\u0441\u043b\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e DI, \u0442\u043e \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0434\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0421\u0442\u043e\u043f-\u0441\u0442\u043e\u043f, \u0432\u0435\u0434\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0446\u0435\u043b\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432 PHP \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432! \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"http:\/\/php.net\/manual\/en\/function.spl-autoload-register.php\">spl_autoload_register<\/a>. <br \/>  \u0414\u0430, \u043c\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043d\u0430 \u0434\u0432\u043e\u0439\u043d\u0438\u043a, \u043d\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u043e\u043c \u0436\u0435 namespace \u0447\u0442\u043e \u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439. \u0422\u043e \u0435\u0441\u0442\u044c \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u043e\u0439\u043d\u0438\u043a \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 \u0441\u0443\u043f\u0435\u0440-\u043a\u043b\u0430\u0441\u0441.<br \/>  \u041d\u0438\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e <a href=\"https:\/\/getcomposer.org\/apidoc\/master\/Composer\/Autoload\/ClassLoader.html\">Composer ClassLoader<\/a>:<\/p>\n<pre><code class=\"php\">class Test extends BaseTest {     public function testStartException() {         $this-&gt;getComposerLoader()-&gt;addClassMap(array(             'App\\Engine' =&gt; &quot;{$this-&gt;appPath}\/src\/Tests\/Mocks\/Autoload\/Engine.php&quot;,         ));         $car = new Car;         $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a, \u0442\u043e \u0432\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c. <br \/>  \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b-\u0434\u0432\u043e\u0439\u043d\u0438\u043a, \u0438\u043d\u043e\u0433\u0434\u0430 \u0432 \u0434\u0432\u043e\u0439\u043d\u0438\u043a\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u0430, \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0442\u0435\u0441\u0442\u043e\u0432 \u0430\u0434\u0441\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0439. \u0421\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0432\u0443\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u043c namespace \u043c\u043e\u0436\u0435\u0442 \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  <b>6.<\/b> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0439\u0442\u0438 \u0435\u0449\u0435 \u0433\u043b\u0443\u0431\u0436\u0435, \u0438 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0444\u0430\u0439\u043b\u043e\u0432, \u043d\u043e \u0445\u043e\u0442\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 PHP-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <a href=\"https:\/\/github.com\/php-test-helpers\/php-test-helpers\">php-test-helpers<\/a>, \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u043b \u0440\u0443\u043a\u0443 Sebastian Bergmann. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0443\u043c\u0435\u0435\u0442 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b exit\/die, \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0432\u0435\u0448\u0430\u0442\u044c callback \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new (\u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 github). \u0422\u043e, \u0447\u0442\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">&lt;?php class Foo {} class Bar {}  var_dump(get_class(new Foo));  set_new_overload(function ($className) {     if ($className == 'Foo') {         $className = 'Bar';     }     return $className; }); var_dump(get_class(new Foo)); <\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"bash\">string(3) &quot;Foo&quot; string(3) &quot;Bar&quot; <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0432 \u044f\u0437\u044b\u043a\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f set_new_overload, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u0440\u043c\u0438\u0442\u044c callback, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435, \u0434\u0430\u0436\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e namespace. \u041c\u044b \u0432\u0438\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u0432 \u0430\u0432\u0442\u043e\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u043c \u0432\u0438\u0434\u0435. \u0422\u0435\u0441\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0430\u043a\u043e\u0439 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"php\">class Test extends BaseTest {     private $overrideClasses = array(         'App\\Engine' =&gt; 'Tests\\Mocks\\Engine',     );      protected function setUp() {         parent::setUp();         if (!function_exists('set_new_overload')) {             $this-&gt;fail('Extension is not available: https:\/\/github.com\/php-test-helpers\/php-test-helpers');         }     }      public function testStartException() {         $overrideClasses = $this-&gt;overrideClasses;         set_new_overload(function ($className) use ($overrideClasses) {             if (isset($overrideClasses[$className])) {                 $className = $overrideClasses[$className];             }             return $className;         });         $car = new Car;         $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435, \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f<\/b><\/p>\n<div class=\"spoiler_text\">1. \u041d\u0430 Linux \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 pear, \u043d\u043e \u043d\u0430 \u043c\u043e\u0435\u043c Debian Wheezy \u044d\u0442\u043e \u043d\u0435 \u0437\u0430\u0432\u0435\u043b\u043e\u0441\u044c. \u041d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"bash\">apt-get install php5-dev git clone git@github.com:php-test-helpers\/php-test-helpers.git php-test-helpers cd php-test-helpers phpize .\/configure make install <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043a\u0430\u043a php-\u043c\u043e\u0434\u0443\u043b\u044c (\u043d\u0435 zend-\u043c\u043e\u0434\u0443\u043b\u044c) \u0432 \u0432\u0430\u0448\u0435\u043c php.ini.<br \/>  \u0414\u043b\u044f \u043e\u0441\u043e\u0431\u043e \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u0432\u043e\u0442 \u043c\u043e\u0439 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 .so \u0434\u043b\u044f PHP 5.4:<br \/>  <a href=\"https:\/\/github.com\/theravel\/unit-tests-article\/blob\/master\/scripts\/extensions\/test_helpers.so\">github.com\/theravel\/unit-tests-article\/blob\/master\/scripts\/extensions\/test_helpers.so<\/a><br \/>  (\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0432\u0441\u0435\u0445 Debian\/Ubuntu \u0441 PHP 5.4, \u043d\u043e \u0432\u0440\u044f\u0442 \u043b\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 PHP \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 OS).<\/p>\n<p>  2. \u041d\u0430 Windows\u2026 \u0432\u0441\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430 (\u0432\u0430\u043c \u043f\u0440\u0430\u0432\u0434\u0430 \u043d\u0443\u0436\u043d\u0430 dll \u043f\u043e\u0434 windows?). \u041d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/github.com\/php-test-helpers\/php-test-helpers\/issues\/6\">\u0431\u0430\u0433<\/a>, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 pear \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 .dll \u043e\u0442\u0441\u044e\u0434\u0430:<br \/>  <a href=\"http:\/\/downloads.php.net\/pierre\/\">downloads.php.net\/pierre\/<\/a><br \/>  \u0425\u043e\u0442\u044f, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0442\u0430\u043c \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u0438, \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f PHP 5.3. \u0415\u0441\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043d\u0443\u0436\u043d\u043e, \u0442\u043e \u044f \u043c\u043e\u0433\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 win.<\/div>\n<\/div>\n<p>  <b>7.<\/b> \u0412 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043e\u0442\u043a\u0440\u044b\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0438\u0445, \u0430 \u0438\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"php\">namespace Tests\\Mocks;  use App\\Cars;  class Car extends Cars\\Car {     public function __construct() {         parent::__construct();         $this-&gt;engine = new Engine;     } } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">namespace Tests;  class Test extends BaseTest {     public function testStartException() {         $car = new Mocks\\Car;         $this-&gt;setExpectedException('CarException');         $car-&gt;start();     } } <\/code><\/pre>\n<p>  \u0412\u0435\u0441\u044c\u043c\u0430 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438: \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0442\u0435\u0441\u0442\u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c mock-\u043a\u043b\u0430\u0441\u0441, \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u043b\u043e\u0441\u044c \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0430-\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f (\u0434\u0430 \u0434\u0430, \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0438 \u0432 \u0442\u0430\u043a\u0443\u044e \u043a\u0440\u0430\u0439\u043d\u043e\u0441\u0442\u044c).<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u0435 \u043b\u0435\u043d\u0438\u0442\u0435\u0441\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, unit-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u043c.<\/p>\n<p>  \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:  <\/p>\n<ul>\n<li>Wiki \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f<br \/> \n<ul>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Dependency_inversion_principle\">en.wikipedia.org\/wiki\/Dependency_inversion_principle<\/a> <\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Single_responsibility_principle\">en.wikipedia.org\/wiki\/Single_responsibility_principle<\/a> <\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/SOLID_(object-oriented_design)\">http:\/\/en.wikipedia.org\/wiki\/SOLID_(object-oriented_design)<\/a> <\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Dependency_injection\">en.wikipedia.org\/wiki\/Dependency_injection<\/a> <\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Mutator_method\">en.wikipedia.org\/wiki\/Mutator_method<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\u041c\u0430\u043d\u0443\u0430\u043b\u044b:<br \/> \n<ul>\n<li>Composer: <a href=\"https:\/\/getcomposer.org\">getcomposer.org<\/a><\/li>\n<li>Symfony components: <a href=\"http:\/\/symfony.com\/components\">symfony.com\/components<\/a><\/li>\n<li>PHPUnit: <a href=\"http:\/\/phpunit.de\">phpunit.de<\/a><\/li>\n<li>PHP autoloading: <a href=\"http:\/\/php.net\/manual\/en\/function.spl-autoload-register.php\">php.net\/manual\/en\/function.spl-autoload-register.php<\/a><\/li>\n<li>Pear: <a href=\"http:\/\/pear.php.net\">pear.php.net<\/a> <\/li>\n<li>php-test-helpers: <a href=\"https:\/\/github.com\/php-test-helpers\/php-test-helpers\">github.com\/php-test-helpers\/php-test-helpers<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>  \u041f\u043e\u0449\u0443\u043f\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430 github:<br \/>  <a href=\"https:\/\/github.com\/theravel\/unit-tests-article\">github.com\/theravel\/unit-tests-article<\/a>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/211328\/\"> http:\/\/habrahabr.ru\/post\/211328\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043e Dependency Injection \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0434\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 PHP-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435. \u0414\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043e PHP.<\/p>\n<p>  \u0414\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434?<\/p>\n<pre><code class=\"php\">class Car {     protected $engine;       public function __construct() {         $this-&gt;engine = new Engine();     }      public function start() {         if ($this-&gt;engine-&gt;hasFuel()) {             $this-&gt;engine-&gt;start();         } else {             throw new CarException(self::EXCEPTION_NO_FUEL);         }     } } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 start \u0438, \u0441\u043a\u0430\u0436\u0435\u043c, \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u043e\u043f\u043b\u0438\u0432\u0430 \u0438 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f? \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 Engine \u0438 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 hasFuel, \u0430 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u201c\u0437\u0430\u0448\u0438\u0442\u201d \u0432 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-211328","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/211328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211328"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/211328\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}