Thank you. That was helped.
public function setUp() {
parent::setUp();
$controller = $this->getMock('Cake\Controller\Controller', [
'redirect']);
$this->registry = new ComponentRegistry($controller);
$this->component = new RBruteForceComponent($this->registry);
}
Voala!
2014. november 2., vasárnap 21:56:00 UTC+1 időpontban José Lorenzo a
következőt írta:
>
> You will need to pass a controller instance to the ComponentRegistry,
> otherwise there will be none to get in the component's initialise function
>
> On Sunday, November 2, 2014 3:12:54 PM UTC+1, Radharadhya Dasa wrote:
>>
>> Hi, I am not able to create a test for my plugins component.
>>
>> Component:
>> namespace RBruteForce\Controller\Component;
>>
>> use Cake\Controller\Component;
>> use Cake\Routing\Router;
>> use Cake\ORM\TableRegistry;
>>
>> class RBruteForceComponent extends Component {
>>
>> public function initialize(array $config) {
>> $this->controller = $this->_registry->getController();
>> $this->request = $this->controller->request;
>> $this->response = $this->controller->response;
>> }
>>
>>
>> Test:
>> namespace RBruteForce\Test\TestCase\Controller\Component;
>>
>> use RBruteForce\Controller\Component\RBruteForceComponent;
>> use Cake\TestSuite\TestCase;
>> use Cake\Controller\Controller;
>> use Cake\Controller\ComponentRegistry;
>> use Cake\Network\Request;
>> use Cake\Network\Response;
>>
>> class RBruteForceComponentTest extends TestCase {
>>
>> public $component = null;
>> public $controller = null;
>>
>> public function setUp() {
>> parent::setUp();
>> // Setup our component and fake test controller
>> $collection = new ComponentRegistry();
>> $this->component = new RBruteForceComponent($collection);
>>
>> $request = new Request();
>> $response = new Response();
>> $this->controller = $this->getMock(
>> 'Cake\Controller\Controller',
>> [],
>> [$request, $response]
>> );
>> }
>>
>>
>> If I try to run the test I got the following error mesage:
>> Notice Error: Trying to get property of non-object in
>> [/home/rrd/public_html/plugins/RBruteForce/src/Controller/Component/RBruteForceComponent.php,
>>
>> line 28]
>>
>> Line 28 is:
>> $this->request = $this->controller->request;
>>
>> It seems that $this->controller is not created.
>>
>> Anyone has an idea what is wrong?
>>
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.