[TYPO3-dev] Howto write UnitTests for class attributes of type nested array?

Steffen Müller typo3 at t3node.com
Sat Aug 4 03:27:31 CEST 2012


I'd like to ask you for some UnitTest support.

In the new Logging API we will have a logger class which has a property
writers (array). Basically we have: (code simplified)

class t3lib_log_Logger {

  protected $writers = array();

  public function addWriter($level, t3lib_log_writer_Writer $writer) {
    $this->writers[$level][] = $writer;
    return $this;
  }
}

Each logger can have multiple writers attached to a level.

For example:
t3lib_log_Logger->addWriter(NOTICE, $testWriter);
t3lib_log_Logger->addWriter(NOTICE, $fileWriter);

will result in:

var_dump($writers)

array(1) {
  'NOTICE' =>
  array(2) {
    [0] =>
    string(10) "testWriter"
    [1] =>
    string(10) "fileWriter"
  }
}


Now I would like to write a UnitTest for the addWriter function. But it
fails, because $writers is a nested array.

This is the UnitTest:

/**
  * @test
  */
public function addWriterAddsWriter() {
  $logger = new t3lib_log_Logger('test.core.log');

  $writer = new t3lib_log_writer_Test();
  $logger->addWriter(t3lib_log_Level::NOTICE, $writer);

  $this->markTestSkipped("writers attribute is multi-dimensional - how
to test this?");
  $this->assertAttributeContains($writer, 'writers', $logger);
}

How to fix the UnitTest?


-- 
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Twitter: @t3node - http://twitter.com/t3node



More information about the TYPO3-dev mailing list