Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require-dev": {
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.0",
"phpunit/phpunit": "^12.5",
"respect/coding-standard": "^5.0",
"squizlabs/php_codesniffer": "^4.0"
},
Expand Down
28 changes: 13 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="date.timezone" value="UTC"/>
</php>
<testsuites>
<testsuite name="Rest Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src/</directory>
</include>
</source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
32 changes: 18 additions & 14 deletions tests/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

namespace Respect\Relational;

class DbTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(Db::class)]
class DbTest extends TestCase
{

protected $object;
Expand All @@ -27,41 +31,41 @@ protected function tearDown(): void
unset($this->object);
}

public function testBasicStatement()
public function testBasicStatement(): void
{
$this->assertEquals(
'unit',
$this->object->select('*')->from('sqlite_master')->fetch()->tbl_name
);
}

public function testPassingValues()
public function testPassingValues(): void
{
$line = $this->object->select('*')->from('unit')->where(array('testb' => 'abc'))->fetch();
$this->assertEquals(10, $line->testa);
}

public function testFetchingAll()
public function testFetchingAll(): void
{
$all = $this->object->select('*')->from('unit')->fetchAll();
$this->assertEquals(3, count($all));
}

public function testFetchingClass()
public function testFetchingClass(): void
{
$line = $this->object->select('*')->from('unit')->fetch('Respect\Relational\testFetchingClass');
$this->assertInstanceOF('Respect\Relational\testFetchingClass', $line);
}

public function testFetchingClassArgs()
public function testFetchingClassArgs(): void
{
$line = $this->object->select('*')->from('unit')->fetch('Respect\Relational\testFetchingClassArgs',
array('foo'));
$this->assertInstanceOF('Respect\Relational\testFetchingClassArgs', $line);
$this->assertEquals('foo', $line->testd);
}

public function testFetchingCallback()
public function testFetchingCallback(): void
{
$line = $this->object->select('*')->from('unit')->fetch(
function($row) {
Expand All @@ -72,39 +76,39 @@ function($row) {
$this->assertEquals('test', $line->acid);
}

public function testFetchingInto()
public function testFetchingInto(): void
{
$x = new testFetchingInto;
$line = $this->object->select('*')->from('unit')->where(array('testb' => 'abc'))->fetch($x);
$this->assertEquals('abc', $x->testb);
}

public function testRawSql()
public function testRawSql(): void
{
$all = $this->object->query('select * from unit')->fetchAll();
$this->assertEquals(3, count($all));
}

public function testFetchingArray()
public function testFetchingArray(): void
{
$line = $this->object->select('*')->from('unit')->where(array('testb' => 'abc'))->fetch(\PDO::FETCH_ASSOC);
$this->assertTrue(is_array($line));
}

public function testFetchingArray2()
public function testFetchingArray2(): void
{
$line = $this->object->select('*')->from('unit')->where(array('testb' => 'abc'))->fetch(array());
$this->assertTrue(is_array($line));
}

public function testGetSql()
public function testGetSql(): void
{
$sql = $this->object->select('*')->from('unit')->where(array('testb' => 'abc'))->getSql();
$this->assertEquals('SELECT * FROM unit WHERE testb = ?', (string) $sql);
$this->assertEquals(array('abc'), $sql->getParams());
}

public function testRawSqlWithParams()
public function testRawSqlWithParams(): void
{
$line = $this->object->query('SELECT * FROM unit WHERE testb = ?', array('abc'))->fetch();
$this->assertEquals(10, $line->testa);
Expand All @@ -130,4 +134,4 @@ public function __construct($testd)
$this->testd = $testd;
}

}
}
Loading
Loading