Adding a task to a car object
<p>I have a car object such as:</p>

<pre><code>class DieselCar#206 (2) {
  protected $_options =&gt;
  array(4) {
    'type' =&gt;
    string(6) "diesel"
    'make' =&gt;
    string(5) "chevy"
    'model' =&gt;
    string(4) "2005"
    'OdometerReading' =&gt;
    string(6) "2346km"
  }
  protected $_tasks =&gt;
  array(0) {
  }
}
</code></pre>

<p>This is created via doing this following:</p>

<pre><code>&lt;?php
Class Car{

    protected $_options;

    protected $_tasks = array();

    public function __construct(array $options){
        if(!isset($options)){
            throw new Exception('No Options were set');
        }

        $this-&gt;_options = $options;
    }

    public function __get($key){
        if(isset($this-&gt;_options[$key])){
            return $this-&gt;_options[$key];
        }

    }

    public function __set($key, $value){
        $this-&gt;_options[$key] = $value;
    }

    public function canAddMaintanceTask($task){
        return true;
    }

    public function addMaintanceTask($task){    
        if($this-&gt;canAddMaintanceTask($task)){
            print_r($task); exit;
            $this-&gt;_task = $task;
        }
    }
}
</code></pre>

<p>The car class will create the object you see above. all you need to do is the following:</p>

<pre><code>$array = array(
    'type' =&gt; 'diesel',
    'make' =&gt; 'chevy',
    'model' =&gt; 2005
    'OdometerReading' =&gt;  '2346km'

);

$car = new Car($array)
</code></pre>

<p>from here we need to add this car to something, so lets go ahead and write that class:</p>

<pre><code>&lt;?php

class CarStore{

    protected $_carArray = array();

    public function __construct(){

    }

    public function add($car){
        $this-&gt;_carArray[] = $car;
        return true;
    }

    public function listCars(){
        return $this-&gt;_carArray;
    }

    public function delete($car){
        if(in_array($car, $this-&gt;_carArray)){
            $this-&gt;_carArray = array_udiff($this-&gt;_carArray, array($car), array($this, 'compareObjects'));
            return true;
        }

        return false;
    }

    public function find($car){
        if(in_array($car, $this-&gt;_carArray)){
            //var_dump($this-&gt;_carArray[0]-&gt;type); exit;
            return $this-&gt;_carArray[0];
        }

        return false;
    }

    public function compareObjects($object1, $object2){
        return $object1-&gt;id - $object2-&gt;id;
    }

}
</code></pre>

<p>now all we have to do is the following:</p>

<pre><code>$carStore = new CarStorage();

$carStore-&gt;add($car);
</code></pre>

<p>So we have added the car into the array (our mock database) and now we have to add a task:</p>

<pre><code>$car-&gt;addMaintanceTask('OilChange');
</code></pre>

<p>the problem is, I seem to be adding this oil Change to a null object? I wrote a test in phpunit, ill post the function:</p>

<pre><code>public function testAddTask(){
    $this-&gt;_storage-&gt;add($this-&gt;_car);
    $this-&gt;assertTrue($this-&gt;_car-&gt;addMaintanceTask('OilChange'));
}
</code></pre>

<p><strong>Note:</strong> the $this->_car is set up in SetUpMethod such as:</p>

<pre><code>public function setUp(){
    parent::SetUp();

    $array = array(
        'type' =&gt; 'diesel',
        'make' =&gt; 'chevy',
        'model' =&gt; '2005',
        'OdometerReading' =&gt; '2346km'
    );

    $this-&gt;_car = new DieselCar($array);
    $this-&gt;_storage = new CarStore();
}
</code></pre>

<p>When I run the test I get the error:</p>

<p><strong>Asserting Null is true</strong></p>

<p>So thats everything, the two classes, one for the car, one for the storage and the begining of the test class.</p>

<p>whats going on? why is it null?</p>
