- Add In/InArray support - Add ORDER BY support for `Find` functions - Update dependencies - Implement fixes identified via static analysis Reviewed-on: #5
		
			
				
	
	
		
			100 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * @author Daniel J. Summers <daniel@bitbadger.solutions>
 | |
|  * @license MIT
 | |
|  */
 | |
| 
 | |
| declare(strict_types=1);
 | |
| 
 | |
| namespace Test\Integration\PostgreSQL;
 | |
| 
 | |
| use BitBadger\PDODocument\{Count, Delete, Field};
 | |
| use PHPUnit\Framework\Attributes\TestDox;
 | |
| use PHPUnit\Framework\TestCase;
 | |
| 
 | |
| /**
 | |
|  * PostgreSQL integration tests for the Delete class
 | |
|  */
 | |
| #[TestDox('Delete (PostgreSQL integration)')]
 | |
| class DeleteTest extends TestCase
 | |
| {
 | |
|     /** @var string Database name for throwaway database */
 | |
|     private string $dbName;
 | |
| 
 | |
|     protected function setUp(): void
 | |
|     {
 | |
|         parent::setUp();
 | |
|         $this->dbName = ThrowawayDb::create();
 | |
|     }
 | |
| 
 | |
|     protected function tearDown(): void
 | |
|     {
 | |
|         ThrowawayDb::destroy($this->dbName);
 | |
|         parent::tearDown();
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byId() succeeds when a document is deleted')]
 | |
|     public function testByIdSucceedsWhenADocumentIsDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byId(ThrowawayDb::TABLE, 'four');
 | |
|         $this->assertEquals(4, Count::all(ThrowawayDb::TABLE), 'There should have been 4 documents remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byId() succeeds when a document is not deleted')]
 | |
|     public function testByIdSucceedsWhenADocumentIsNotDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byId(ThrowawayDb::TABLE, 'negative four');
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byFields() succeeds when documents are deleted')]
 | |
|     public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
 | |
|         $this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byFields() succeeds when documents are not deleted')]
 | |
|     public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byContains() succeeds when documents are deleted')]
 | |
|     public function testByContainsSucceedsWhenDocumentsAreDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byContains(ThrowawayDb::TABLE, ['value' => 'purple']);
 | |
|         $this->assertEquals(3, Count::all(ThrowawayDb::TABLE), 'There should have been 3 documents remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byContains() succeeds when documents are not deleted')]
 | |
|     public function testByContainsSucceedsWhenDocumentsAreNotDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byContains(ThrowawayDb::TABLE, ['target' => 'acquired']);
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byJsonPath() succeeds when documents are deleted')]
 | |
|     public function testByJsonPathSucceedsWhenDocumentsAreDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ <> 0)');
 | |
|         $this->assertEquals(1, Count::all(ThrowawayDb::TABLE), 'There should have been 1 document remaining');
 | |
|     }
 | |
| 
 | |
|     #[TestDox('byJsonPath() succeeds when documents are not deleted')]
 | |
|     public function testByJsonPathSucceedsWhenDocumentsAreNotDeleted(): void
 | |
|     {
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
 | |
|         Delete::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ < 0)');
 | |
|         $this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
 | |
|     }
 | |
| }
 |