ソースを参照

Make View::$hasRendered protected as add getter method for it.

ADmad 7 年 前
コミット
0f1519699d
2 ファイル変更24 行追加1 行削除
  1. 11 1
      src/View/View.php
  2. 13 0
      tests/TestCase/View/ViewTest.php

+ 11 - 1
src/View/View.php

@@ -191,7 +191,7 @@ class View implements EventDispatcherInterface
      *
      * @var bool
      */
-    public $hasRendered = false;
+    protected $hasRendered = false;
 
     /**
      * List of generated DOM UUIDs.
@@ -1395,6 +1395,16 @@ class View implements EventDispatcherInterface
     }
 
     /**
+     * Check whether the view has been rendered.
+     *
+     * @return bool
+     */
+    public function hasRendered()
+    {
+        return $this->hasRendered;
+    }
+
+    /**
      * Returns filename of given action's template file (.ctp) as a string.
      * CamelCased action names will be under_scored by default.
      * This means that you can have LongActionNames that refer to

+ 13 - 0
tests/TestCase/View/ViewTest.php

@@ -2136,6 +2136,19 @@ TEXT;
     }
 
     /**
+     * Test testHasRendered()
+     *
+     * @return void
+     */
+    public function testHasRendered()
+    {
+        $this->assertFalse($this->View->hasRendered());
+
+        $this->View->render('index');
+        $this->assertTrue($this->View->hasRendered());
+    }
+
+    /**
      * Test magic getter and setter for removed properties.
      *
      * @group deprecated