Skip to content
Open
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
43 changes: 43 additions & 0 deletions index (3).php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use PHPUnit\Framework\TestCase;

class Migration {
private $pdo;

public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}

public function up() {
$sql = "CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL
)";
$this->pdo->exec($sql);
}

public function down() {
$sql = "DROP TABLE users";
$this->pdo->exec($sql);
}
}

class MigrationTest extends TestCase {
public function testRollbackMigration() {
$pdoMock = $this->getMockBuilder(PDO::class)
->disableOriginalConstructor()
->getMock();

$migrationMock = $this->getMockBuilder(Migration::class)
->setConstructorArgs([$pdoMock])
->onlyMethods(['up', 'down'])
->getMock();

$migrationMock->expects($this->once())
->method('down');

$migrationMock->down();
}
}