CI_Unit with non-CI_Controller class - php

I recently installed the CI_UNIT test environment for my ci application. The preinstalled tests ran as they should but when I tried to test one of my controllers, it crashed at the line
$this->CI = set_controller('...');
of the controller test class without throwing an error. I found out, that it depends on the class from which I inherit the controller. In my current application I have three levels of inheritance.
The built in CI_Controller
A class that extends CI_Controller and which provides functions that are specific for any kind of controller of this application: The APP_Controller.
Some classes that extend the APP_Controller and where one of these, in this case provides functions only interesting for the REST API of the application.
The CI_UNIT however seems to work if and only if the controller directly inherits from CI_Controller. How can I get around this?

Related

Laravel Binding Service Provider Concept

Im currently learning how laravel framework builded and came to service provider section. in class DatabaseServiceProvider which extends ServiceProvider class i see this line of code :
$this->app->singleton('db.factory', function ($app)
{
return new ConnectionFactory($app);
});
im confuse what is app in $this->app, whether app is an object from application class instance and if it does when it is instantiated so it can be used from DatabaseServiceProvider class since i dont see its instantiation process. thnks before for answering this newbie question.
In Laravel, the app variable is a service container. Think of it like a heart of the framework. Everything you use from Facades to DB connections is stored in there.
Moreover, you can store your own objects in the container by using the method you specified ($this->app->singleton()). There are actualy many more ways to interact with the container. The best way to research this is to look into Laravel's documentation (Laravel Service Container)
The app object is being instantiated on Laravel bootstrap so you can't see it in the service provider. Though I was curious enough to dig deep into the framework to find it. The class itself is located in Illuminate\Foundation\Application and is instantiated in bootstrap/app.php.

Laravel 5.1: Class that implements a base PHP interface errors out

I've been working on modifying/converting the Recurly PHP client library to work in Laravel 5.1.
I got namespacing to work to the point that I can reference the Recurly library classes appropriately, but have run into the wall of interfaces that those classes implement causing the classes to fail out.
As a note: these interfaces are base php interfaces, but I can't figure out how to get Laravel 5.1 to let a class implement a base php interface that isn't a 'baked-in' Laravel interface.
System PHP version: 5.6.22
Example Class declaration causing issues:
<?php
namespace App\Libraries\Recurly;
class Recurly_CurrencyList implements ArrayAccess, Countable, IteratorAggregate
{
This is the error message that gets thrown:
Interface 'App\Libraries\Recurly\ArrayAccess' not found

Nested classes in PHP

Recently, I came across a situation where I need to use nested classes in my code.
Actually, I have implemented Threading in php, I am using worker and concept of pooling in threads.
I have developed the application in YII framework, threads basically perform some computation and I need to save that computation into the database.
I cannot access the YII framework model files in the thread class since the thread class doesn't know anything about the YII framework. If I somehow make the MyCustomThread class as the nested classes within YII, that will be the property of YII super class and all the operations can be done easily.
I looked into the concept of namespace but it didn't work probably my child class extend the THREADED class which causes the problem.
Your thoughts please??

How do you find methods in the Zend Framework 2 API

I'm trying to find utility in the Zend Framework 2 API but can't. Maybe I'm not using it right.
For example, following the online documentation for Unit Testing in Zend Framework:
http://framework.zend.com/manual/2.3/en/tutorials/unittesting.html
... I see that a class that extends AbstractHttpControllerTestCase inherits access to $this->getMockBuilder() from somewhere. However I cannot find it in the API documentation for the AbstractHttpControllerTestCase class:
http://framework.zend.com/apidoc/2.3/classes/Zend.Test.PHPUnit.Controller.AbstractHttpControllerTestCase.html
I also don't see a search utility anywhere in the API. How can one know what methods are available to an extension of this class? Dig into the code? Then why publish a partial formal API?
That class extends phpunit test case to provide additional functionality for controller testing.
For PHPUnit_Framework_TestCase usage refer to phpunit documentation
As for how i find methods - i browse code, parent classes and such. Others use their IDE features.

PHP Unit Test: How to test a class that implements an interface from another package?

I am trying to test a class that implements an interface that is defined outside the scope of the classes package (i.e. I pull it in as a dependency using composer during integration).
I would like to test this concrete class without having to pull in the interface it depends on. Is there anyway to test this in php unit test?
At the moment I can't even instantiate an instance as the interface is obviously not found.
The interface that your class is not a dependency in that sense... There is nothing to mock. You just need to make sure that the class is an instance of the interface in your tests for that class.
You need to change something about your testing environment so that the interface is available in order to test your class. So that you can instantiate and test the behavior of the methods that the interface specifies.
Dependency injection is about objects that your code NEEDS not what your code is. An interface or an abstract class are not dependencies. Even though your code "depends" on those things existing.
Dependencies are external objects that you class needs to do something. Interfaces and abstract classes define what are you class is.

Categories