Skip to content

Commit

Permalink
FEAT: try to add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
drosanda committed Nov 8, 2024
1 parent 345d710 commit 43395c7
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 49 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: PHP Lint Check

on:
push:
branches: [ "unittest" ]
pull_request:
branches: [ "unittest" ]

permissions:
contents: read

jobs:
build:

runs-on: self-hosted

steps:

- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: PHP lint
run: |
lint_errors=$(find app kero/sine -type f -name "*.php" -exec php -l {} \; 2>&1)
echo "$lint_errors"
if grep -q "Parse error" <<< "$lint_errors"; then
exit 1
fi
- name: Run PHPUnit tests
run: |
vendor\bin\phpunit.bat --configuration phpunit.xml --testsuite Dev
75 changes: 42 additions & 33 deletions dev/test/SENE_Controller_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function invokeMethod(&$object, $methodName, array $parameters = array())
return $method->invokeArgs($object, $parameters);
}

/**
* @covers SENE_Controller::setTitle()
* @covers SENE_Controller::getTitle()
*/
public function testTitle()
{
$tc = new SENE_Controller_Mock();
Expand All @@ -45,6 +49,10 @@ public function testTitle()
$this->assertNotEquals(strtolower($ts), $this->invokeMethod($tc, 'getTitle', array()));
}

/**
* @covers SENE_Controller::setDescription()
* @covers SENE_Controller::getDescription()
*/
public function testDescription()
{
$tc = new SENE_Controller_Mock();
Expand All @@ -53,7 +61,11 @@ public function testDescription()
$this->assertEquals($ts, $this->invokeMethod($tc, 'getDescription', array()));
$this->assertNotEquals(strtolower($ts), $this->invokeMethod($tc, 'getDescription', array()));
}


/**
* @covers SENE_Controller::setLang()
* @covers SENE_Controller::getLang()
*/
public function testLang()
{
$tc = new SENE_Controller_Mock();
Expand All @@ -62,7 +74,11 @@ public function testLang()
$this->assertEquals($ts, $this->invokeMethod($tc, 'getLang', array()));
$this->assertNotEquals(strtolower($ts), $this->invokeMethod($tc, 'getLang', array()));
}


/**
* @covers SENE_Controller::setRobots()
* @covers SENE_Controller::getRobots()
*/
public function testRobots()
{
$tc = new SENE_Controller_Mock();
Expand All @@ -83,7 +99,11 @@ public function testRobots()
$this->assertEquals('INDEX', $this->invokeMethod($tc, 'getRobots', array()));
$this->assertNotEquals(strtolower(''), $this->invokeMethod($tc, 'getRobots', array()));
}


/**
* @covers SENE_Controller::setAuthor()
* @covers SENE_Controller::getAuthor()
*/
public function testAuthor()
{
$tc = new SENE_Controller_Mock();
Expand All @@ -93,9 +113,8 @@ public function testAuthor()
}

/**
*
*
*
* @covers SENE_Controller::setIcon()
* @covers SENE_Controller::getIcon()
*/
public function testIcon()
{
Expand All @@ -106,9 +125,8 @@ public function testIcon()
}

/**
*
*
*
* @covers SENE_Controller::setShortcutIcon()
* @covers SENE_Controller::getShortcutIcon()
*/
public function testShortcutIcon()
{
Expand Down Expand Up @@ -202,9 +220,8 @@ public function testTheme()
}

/**
*
*
*
* @covers SENE_Controller::setcanonical
* @covers SENE_Controller::getcanonical
*/
public function testCanonicalEmpty()
{
Expand All @@ -231,9 +248,8 @@ public function testCanonicalEmpty()
}

/**
*
*
*
* @covers SENE_Controller::setadditional
* @covers SENE_Controller::getadditional
*/
public function testSetAdditional()
{
Expand All @@ -245,9 +261,8 @@ public function testSetAdditional()
}

/**
*
*
*
* @covers SENE_Controller::setadditional
* @covers SENE_Controller::getadditional
*/
public function testGetAdditionalPlain()
{
Expand All @@ -261,9 +276,8 @@ public function testGetAdditionalPlain()
}

/**
*
*
*
* @covers SENE_Controller::setadditional
* @covers SENE_Controller::getadditional
*/
public function testGetAdditionalBaseUrl()
{
Expand All @@ -277,9 +291,8 @@ public function testGetAdditionalBaseUrl()
}

/**
*
*
*
* @covers SENE_Controller::setadditional
* @covers SENE_Controller::getadditional
*/
public function testGetAdditionalBaseUrlAdmin()
{
Expand All @@ -293,9 +306,8 @@ public function testGetAdditionalBaseUrlAdmin()
}

/**
*
*
*
* @covers SENE_Controller::setadditional
* @covers SENE_Controller::getadditional
*/
public function testGetAdditionalCdnUrl()
{
Expand All @@ -310,9 +322,7 @@ public function testGetAdditionalCdnUrl()
}

/**
*
*
*
* @covers SENE_Controller::setadditionalbefore
*/
public function testSetAdditionalBefore()
{
Expand All @@ -324,9 +334,8 @@ public function testSetAdditionalBefore()
}

/**
*
*
*
* @covers SENE_Controller::setadditionalbefore
* @covers SENE_Controller::getadditionalbefore
*/
public function testGetAdditionalBeforePlain()
{
Expand Down
9 changes: 3 additions & 6 deletions dev/test/SENE_Input_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ public function testPost()
}

/**
*
*
*
* @covers SENE_Input::get
* @covers SENE_Input::post
*/
public function testGet()
{
Expand All @@ -87,9 +86,7 @@ public function testGet()
}

/**
*
*
*
* @covers SENE_Input::request
*/
public function testRequest()
{
Expand Down
27 changes: 17 additions & 10 deletions dev/test/SENE_MySQLi_Engine_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);
// Path to run ./vendor/bin/phpunit --bootstrap vendor/autoload.php FileName.php
// Butuh Framework PHPUnit
use PHPUnit\Framework\TestCase;

require_once $GLOBALS['SEMEDIR']->kero_sine.'SENE_Sql.php';
require_once $GLOBALS['SEMEDIR']->kero_sine.'SENE_Sql_Select.php';
Expand All @@ -24,7 +23,7 @@ public function __construct()
#[UsesClass('SENE_MySQLi_Engine_Mock')]
#[CoversClass('SENE_MySQLi_Engine')]
#[CoversClass('SENE_Model')]
final class SENE_MySQLi_Engine_Test extends TestCase
final class SENE_MySQLi_Engine_Test extends PHPUnit\Framework\TestCase
{
/**
* Call protected/private method of a class.
Expand All @@ -44,7 +43,7 @@ public function invokeMethod(&$object, $methodName, array $parameters = array())
}

/**
*
* @covers SENE_MySQLi_Engine::flushQuery
*
*/
public function testFlushQuery()
Expand All @@ -64,7 +63,7 @@ public function testFlushQuery()
}

/**
*
* @covers SENE_MySQLi_Engine::flushQuery
*
*/
public function testFlushQueryAfter()
Expand All @@ -87,7 +86,7 @@ public function testFlushQueryAfter()
}

/**
*
* @covers SENE_MySQLi_Engine::flushQuery
*
*/
public function testWhereIsNull()
Expand All @@ -113,7 +112,9 @@ public function testWhereIsNull()
}

/**
*
* @covers SENE_MySQLi_Engine::select
* @covers SENE_MySQLi_Engine::from
* @covers SENE_MySQLi_Engine::where
*
*/
public function testWhereIsNotNull()
Expand All @@ -139,7 +140,9 @@ public function testWhereIsNotNull()
}

/**
*
* @covers SENE_MySQLi_Engine::select
* @covers SENE_MySQLi_Engine::from
* @covers SENE_MySQLi_Engine::where
*
*/
public function testWhereAsIsNull()
Expand All @@ -165,7 +168,8 @@ public function testWhereAsIsNull()
}

/**
*
* @covers SENE_MySQLi_Engine::where_as
* @covers SENE_MySQLi_Engine::where
*
*/
public function testWhereAsIsNotNull()
Expand All @@ -191,7 +195,9 @@ public function testWhereAsIsNotNull()
}

/**
*
* @covers SENE_MySQLi_Engine::select
* @covers SENE_MySQLi_Engine::from
* @covers SENE_MySQLi_Engine::where
*
*/
public function testWhere()
Expand Down Expand Up @@ -302,7 +308,8 @@ public function testWhere()
}

/**
*
* @covers SENE_MySQLi_Engine::where_as
* @covers SENE_MySQLi_Engine::where
*
*/
public function testWhereAs()
Expand Down

0 comments on commit 43395c7

Please sign in to comment.