Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more tests
  • Loading branch information
Roger Hughes committed Jan 7, 2022
1 parent 21f19e2 commit 88783a3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/sample.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
'Timezone' => 'Europe/London',
'ViewPath' => __DIR__ . '/Views/',
// optional
'DBHost' => '',
'DBName' => '',
'DBUser' => '',
'DBPassword' => '',
'DBHost' => '127.0.0.1',
'DBName' => 'graft',
'DBUser' => 'root',
'DBPassword' => 'root',
'DBPort' => 3306,
];

Expand Down
33 changes: 33 additions & 0 deletions tests/DBTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
use PHPUnit\Framework\TestCase;

final class DBTest extends TestCase
{
public function testConnection(): void
{
$db = new GraftPHP\Framework\DB();

$this->assertInstanceOf(
GraftPHP\Framework\DB::class,
$db,
);
}

public function testTableDoesntExist(): void
{
$this->assertEquals(
false,
GraftPHP\Framework\DB::tableExists('testtable')
);
}

public function testCreateTable(): void
{
$db = new GraftPHP\Framework\DB();
$db->createTable('testtable');
$this->assertEquals(
false,
GraftPHP\Framework\DB::tableExists('testtable')
);
}
}
12 changes: 6 additions & 6 deletions tests/FrameworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ function setUp(): void
public function testRouting404(): void
{
$this->assertEquals(
$this->framework->matchRoute('/doesnotexist'),
false
false,
$this->framework->matchRoute('/doesnotexist')
);
}

public function testRoutingExact(): void
{
$this->assertEquals(
$this->framework->matchRoute(GRAFT_HTTP_ROUTES[0][0]),
GRAFT_HTTP_ROUTES[0]
GRAFT_HTTP_ROUTES[0],
$this->framework->matchRoute(GRAFT_HTTP_ROUTES[0][0])
);
}

public function testRoutingWildcard(): void
{
$url = str_replace('{}', uniqid(), GRAFT_HTTP_ROUTES[2][0]);
$this->assertEquals(
$this->framework->matchRoute($url),
GRAFT_HTTP_ROUTES[2]
GRAFT_HTTP_ROUTES[2],
$this->framework->matchRoute($url)
);
}
}
4 changes: 2 additions & 2 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ final class FunctionsTest extends TestCase
public function testUrlSafe(): void
{
$this->assertEquals(
GraftPHP\Framework\Functions::urlSafe('£%@\'---ABCD123'),
'abcd123'
'abcd123',
GraftPHP\Framework\Functions::urlSafe('£%@\'---ABCD123')
);
}
}
12 changes: 6 additions & 6 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ final class ViewTest extends TestCase
public function testBasicView(): void
{
$this->assertEquals(
GraftPHP\Framework\View::Render('tests.basic',null,null,true),
'HELLO WORLD'
'HELLO WORLD',
GraftPHP\Framework\View::Render('tests.basic',null,null,true)
);
}

public function testTemplateView(): void
{
$this->assertEquals(
GraftPHP\Framework\View::Render('tests.template_child',null,null,true),
'TEMPLATECHILD'
'TEMPLATECHILD',
GraftPHP\Framework\View::Render('tests.template_child',null,null,true)
);
}

public function testTemplateEmbed(): void
{
$this->assertEquals(
GraftPHP\Framework\View::Render('tests.embed_parent',null,null,true),
'PARENTCHILD'
'PARENTCHILD',
GraftPHP\Framework\View::Render('tests.embed_parent',null,null,true)
);
}
}

0 comments on commit 88783a3

Please sign in to comment.