tests/GameOfLife/Inputs/TemplateHandler/TemplateLoaderTest.php
/**
     * Checks whether templates are correctly loaded.
     *
     * @throws \Exception
     */
Checks whether templates are correctly loaded.
@throws \Exception
Checks whether templates are correctly loaded . @throws \ Exception
public function testCanLoadTemplate()
    {
        $board = new Board(5, 5, 1, true);
        $templateFields = $this->templateLoader->loadTemplate("unittest");
        $templateHeight = count($templateFields);
        $templateWidth = count($templateFields[0]);
        $this->assertEquals(2, $templateWidth);
        $this->assertEquals(2, $templateHeight);
        $this->assertTrue($templateFields[0][0]->isAlive());
        $this->assertFalse($templateFields[1][0]->isAlive());
        $this->assertFalse($templateFields[0][1]->isAlive());
        $this->assertFalse($templateFields[1][1]->isAlive());
        $this->fileSystemWriter->writeFile($this->templateDirectory . "/Custom/unittest2.txt", ".X\r\n..");
        $templateFields = $this->templateLoader->loadTemplate("unittest2");
        $templateHeight = count($templateFields);
        $templateWidth = count($templateFields[0]);
        $this->assertEquals(2, $templateWidth);
        $this->assertEquals(2, $templateHeight);
        $this->assertFalse($templateFields[0][0]->isAlive());
        $this->assertTrue($templateFields[0][1]->isAlive());
        $this->assertFalse($templateFields[1][0]->isAlive());
        $this->assertFalse($templateFields[1][1]->isAlive());
        $this->fileSystemWriter->deleteFile($this->templateDirectory . "/Custom/unittest2.txt");
        try
        {
            $this->fileSystemWriter->deleteDirectory($this->templateDirectory . "/Custom");
        }
        catch (\Exception $_exception)
        {
        }
        $exceptionOccurred = false;
        try
        {
            $this->templateLoader->loadTemplate("invalidTemplate");
        }
        catch (\Exception $_exception)
        {
            $exceptionOccurred = true;
            $this->assertEquals("The template file could not be found.", $_exception->getMessage());
        }
        $this->assertTrue($exceptionOccurred);
    }
public function testCanLoadTemplate ( ) { $ board = new Board ( 5 , 5 , 1 , true ) ; $ templateFields = $ this -> templateLoader -> loadTemplate ( " unittest " ) ; $ templateHeight = count ( $ templateFields ) ; $ templateWidth = count ( $ templateFields [ 0 ] ) ; $ this -> assertEquals ( 2 , $ templateWidth ) ; $ this -> assertEquals ( 2 , $ templateHeight ) ; $ this -> assertTrue ( $ templateFields [ 0 ] [ 0 ] -> isAlive ( ) ) ; $ this -> assertFalse ( $ templateFields [ 1 ] [ 0 ] -> isAlive ( ) ) ; $ this -> assertFalse ( $ templateFields [ 0 ] [ 1 ] -> isAlive ( ) ) ; $ this -> assertFalse ( $ templateFields [ 1 ] [ 1 ] -> isAlive ( ) ) ; $ this -> fileSystemWriter -> writeFile ( $ this -> templateDirectory . " /Custom/unittest2.txt " , " .X \r \n .. " ) ; $ templateFields = $ this -> templateLoader -> loadTemplate ( " unittest2 " ) ; $ templateHeight = count ( $ templateFields ) ; $ templateWidth = count ( $ templateFields [ 0 ] ) ; $ this -> assertEquals ( 2 , $ templateWidth ) ; $ this -> assertEquals ( 2 , $ templateHeight ) ; $ this -> assertFalse ( $ templateFields [ 0 ] [ 0 ] -> isAlive ( ) ) ; $ this -> assertTrue ( $ templateFields [ 0 ] [ 1 ] -> isAlive ( ) ) ; $ this -> assertFalse ( $ templateFields [ 1 ] [ 0 ] -> isAlive ( ) ) ; $ this -> assertFalse ( $ templateFields [ 1 ] [ 1 ] -> isAlive ( ) ) ; $ this -> fileSystemWriter -> deleteFile ( $ this -> templateDirectory . " /Custom/unittest2.txt " ) ; try { $ this -> fileSystemWriter -> deleteDirectory ( $ this -> templateDirectory . " /Custom " ) ; } catch ( \ Exception $ _exception ) { } $ exceptionOccurred = false ; try { $ this -> templateLoader -> loadTemplate ( " invalidTemplate " ) ; } catch ( \ Exception $ _exception ) { $ exceptionOccurred = true ; $ this -> assertEquals ( " The template file could not be found. " , $ _exception -> getMessage ( ) ) ; } $ this -> assertTrue ( $ exceptionOccurred ) ; }
Checks whether templates are correctly loaded.
Checks whether templates are correctly loaded .
// Official template /** @var Field[][] $templateFields */ // Custom template /** @var Field[][] $templateFields */ // Ignore exception // Non existent template