Skip to content

Commit

Permalink
v1.2.0 - Add Drop Class
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevick committed Oct 31, 2021
1 parent 25f5947 commit 992a7b3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
18 changes: 18 additions & 0 deletions src/classes/Drop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace DinoDev\MySql\Classes;

class Drop extends MySql
{
protected MySql $MySql;

public function __construct(MySql $_MySql)
{
$this->MySql = $_MySql;
}

public function Table(string $tableName)
{
return $this->MySql->query("DROP TABLE $tableName");
}
}
11 changes: 5 additions & 6 deletions tests/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use PHPUnit\Framework\TestCase;
use DinoDev\MySql\Classes\MySql;
use DinoDev\MySql\Classes\Create;
use DinoDev\MySql\Classes\Drop;

require_once __DIR__ . "/../vendor/autoload.php";

Expand All @@ -20,15 +21,13 @@ protected function setUp(): void
public function testTable()
{
//Drop table, case exists
$this->dropTestTable();
$Drop = new Drop($this->MySql);
$Drop->Table("Test");

$this->assertTrue($this->Create->Table("Test", ["Value 1", "Value 2"], ["varchar(20)", "varchar(20)"]));

$this->assertFalse($this->Create->Table("Test", ["Value 1", "Value 2"], ["varchar(20)", "varchar(20)"]));
}

public function dropTestTable()
{
$this->MySql->query("DROP TABLE Test");

$Drop->Table("Test");
}
}
18 changes: 11 additions & 7 deletions tests/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use PHPUnit\Framework\TestCase;
use DinoDev\MySql\Classes\MySql;
use DinoDev\MySql\Classes\Delete;
use DinoDev\MySql\Classes\Drop;
use DinoDev\MySql\Classes\Insert;
use DinoDev\MySql\Classes\Create;

require_once __DIR__ . "/../vendor/autoload.php";

Expand All @@ -18,41 +20,43 @@ protected function setUp(): void
$this->Delete = new Delete($this->MySql);

//Create a Temporary Table
$this->MySql->queryAndFetch("CREATE TABLE IF NOT EXISTS TempTable ( TestValue varchar(50) )");
$Create = new Create($this->MySql);
$Create->Table("Test", ["TestValue"], ["varchar(50)"]);
}

protected function tearDown(): void
{
//Delete the Temporary Table
$this->MySql->queryAndFetch("DROP TABLE temptable");
$Drop = new Drop($this->MySql);
$Drop->Table("Test");
}

public function testAll()
{
//Delete
$this->assertTrue($this->Delete->All("TempTable"));
$this->assertTrue($this->Delete->All("Test"));
$this->assertFalse($this->Delete->All("NoTable"));
}

public function testWhere()
{
//Insert a Value
$Insert = new Insert($this->MySql);
$Insert->Insert("TempTable", ["TestValue"], ["Hello"]);
$Insert->Insert("Test", ["TestValue"], ["Hello"]);

//Delete
$this->assertTrue($this->Delete->Where("TempTable", "TestValue", "Hello"));
$this->assertTrue($this->Delete->Where("Test", "TestValue", "Hello"));
$this->assertFalse($this->Delete->Where("NoTable", "TestValue", "Hello"));
}

public function testLike()
{
//Insert a Value
$Insert = new Insert($this->MySql);
$Insert->Insert("TempTable", ["TestValue"], ["Hello"]);
$Insert->Insert("Test", ["TestValue"], ["Hello"]);

//Delete
$this->assertTrue($this->Delete->Like("TempTable", "TestValue", "Hello"));
$this->assertTrue($this->Delete->Like("Test", "TestValue", "Hello"));
$this->assertFalse($this->Delete->Like("NoTable", "TestValue", "Hello"));
}
}
8 changes: 5 additions & 3 deletions tests/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use DinoDev\MySql\Classes\MySql;
use DinoDev\MySql\Classes\Insert;
use DinoDev\MySql\Classes\Create;
use DinoDev\MySql\Classes\Drop;

require_once __DIR__ . "/../vendor/autoload.php";

Expand All @@ -22,13 +23,14 @@ public function testInsert()
{
//Create a Temporary Table
$Create = new Create($this->MySql);
$Create->Table("TempTable", ["TestValue"], ["varchar(50)"]);
$Create->Table("Test", ["TestValue"], ["varchar(50)"]);

//Insert
$this->assertTrue($this->Insert->Insert("TempTable", ["TestValue"], ["Hello"]));
$this->assertTrue($this->Insert->Insert("Test", ["TestValue"], ["Hello"]));
$this->assertFalse($this->Insert->Insert("NoTable", [], []));

//Delete the Temporary Table
$this->MySql->queryAndFetch("DROP TABLE temptable");
$Drop = new Drop($this->MySql);
$Drop->Table("Test");
}
}

0 comments on commit 992a7b3

Please sign in to comment.