Skip to content

Commit 619c730

Browse files
authored
Merge pull request #2 from woohoolabs/add-tests
Add tests for Worm
2 parents 34e6427 + ea36c21 commit 619c730

4 files changed

Lines changed: 227 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace WoohooLabs\Worm\Tests\Connection;
4+
namespace WoohooLabs\Worm\Tests\Execution;
55

66
use PHPUnit\Framework\TestCase;
77
use stdClass;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace WoohooLabs\Worm\Tests\TestDouble;
5+
6+
use WoohooLabs\Larva\Connection\ConnectionInterface;
7+
use WoohooLabs\Larva\Driver\DriverInterface;
8+
use WoohooLabs\Larva\Driver\MySql\MySqlDriver;
9+
10+
class DummyConnection implements ConnectionInterface
11+
{
12+
public function fetchAll(string $sql, array $params = []): array
13+
{
14+
return [];
15+
}
16+
17+
public function fetch(string $sql, array $params = []): iterable
18+
{
19+
return [];
20+
}
21+
22+
public function fetchColumn(string $sql, array $params = [])
23+
{
24+
return null;
25+
}
26+
27+
public function execute(string $sql, array $params = []): bool
28+
{
29+
return false;
30+
}
31+
32+
public function beginTransaction(): bool
33+
{
34+
return true;
35+
}
36+
37+
public function commit(): bool
38+
{
39+
return true;
40+
}
41+
42+
public function rollback(): bool
43+
{
44+
return true;
45+
}
46+
47+
public function getLastInsertedId(?string $name = null): string
48+
{
49+
return "";
50+
}
51+
52+
public function getDriver(): DriverInterface
53+
{
54+
return new MySqlDriver();
55+
}
56+
57+
public function getLog(): array
58+
{
59+
return [];
60+
}
61+
}

tests/TestDouble/DummyModel.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace WoohooLabs\Worm\Tests\TestDouble;
5+
6+
use WoohooLabs\Larva\Query\Condition\ConditionBuilder;
7+
use WoohooLabs\Larva\Query\Condition\ConditionBuilderInterface;
8+
use WoohooLabs\Worm\Execution\IdentityMap;
9+
use WoohooLabs\Worm\Execution\Persister;
10+
use WoohooLabs\Worm\Model\ModelInterface;
11+
use WoohooLabs\Worm\Model\Relationship\HasOneRelationship;
12+
use WoohooLabs\Worm\Model\Relationship\RelationshipInterface;
13+
14+
class DummyModel implements ModelInterface
15+
{
16+
public function getTable(): string
17+
{
18+
return "";
19+
}
20+
21+
public function getPrimaryKeys(): array
22+
{
23+
return [];
24+
}
25+
26+
public function getRelationshipNames(): array
27+
{
28+
return [];
29+
}
30+
31+
public function getRelationship(string $name): RelationshipInterface
32+
{
33+
return new HasOneRelationship(new DummyModel(), new DummyModel(), "", "");
34+
}
35+
36+
public function getId(array $record)
37+
{
38+
return "";
39+
}
40+
41+
public function getHash(array $record): string
42+
{
43+
return "";
44+
}
45+
46+
public function getHashFromId($id): string
47+
{
48+
return "";
49+
}
50+
51+
public function createConditionBuilder($id): ConditionBuilderInterface
52+
{
53+
return new ConditionBuilder();
54+
}
55+
56+
public function addRelationshipsToIdentityMap(IdentityMap $identityMap, array $entity): void
57+
{
58+
}
59+
60+
public function cascadeDelete(Persister $persister, $id): void
61+
{
62+
}
63+
}

tests/WormTest.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace WoohooLabs\Worm\Tests;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use WoohooLabs\Worm\Execution\IdentityMap;
8+
use WoohooLabs\Worm\Tests\TestDouble\DummyConnection;
9+
use WoohooLabs\Worm\Tests\TestDouble\DummyModel;
10+
use WoohooLabs\Worm\Worm;
11+
12+
class WormTest extends TestCase
13+
{
14+
/**
15+
* @test
16+
*/
17+
public function query(): void
18+
{
19+
$worm = $this->createWorm();
20+
21+
$worm->query(new DummyModel());
22+
23+
$this->expectNotToPerformAssertions();
24+
}
25+
26+
/**
27+
* @test
28+
*/
29+
public function queryDelete(): void
30+
{
31+
$worm = $this->createWorm();
32+
33+
$worm->queryDelete(new DummyModel());
34+
35+
$this->expectNotToPerformAssertions();
36+
}
37+
38+
/**
39+
* @test
40+
*/
41+
public function queryInsert(): void
42+
{
43+
$worm = $this->createWorm();
44+
45+
$worm->queryInsert(new DummyModel());
46+
47+
$this->expectNotToPerformAssertions();
48+
}
49+
50+
/**
51+
* @test
52+
*/
53+
public function queryTruncate(): void
54+
{
55+
$worm = $this->createWorm();
56+
57+
$worm->queryTruncate(new DummyModel());
58+
59+
$this->expectNotToPerformAssertions();
60+
}
61+
62+
/**
63+
* @test
64+
*/
65+
public function queryUpdate(): void
66+
{
67+
$worm = $this->createWorm();
68+
69+
$worm->queryUpdate(new DummyModel());
70+
71+
$this->expectNotToPerformAssertions();
72+
}
73+
74+
/**
75+
* @test
76+
*/
77+
public function getConnection(): void
78+
{
79+
$worm = $this->createWorm();
80+
81+
$worm->getConnection();
82+
83+
$this->expectNotToPerformAssertions();
84+
}
85+
86+
/**
87+
* @test
88+
*/
89+
public function getIdentityMap(): void
90+
{
91+
$worm = $this->createWorm();
92+
93+
$worm->getIdentityMap();
94+
95+
$this->expectNotToPerformAssertions();
96+
}
97+
98+
private function createWorm(): Worm
99+
{
100+
return new Worm(new DummyConnection(), new IdentityMap());
101+
}
102+
}

0 commit comments

Comments
 (0)