Skip to content
Open
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
30 changes: 19 additions & 11 deletions HelloWorld.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@ public function __construct(PDO $pdo)
}

public function createDBIFNotExists() {
$sql = "CREATE TABLE IF NOT EXISTS hello;";
$this->pdo->query($sql);
return true;
$sql = "CREATE DATABASE IF NOT EXISTS hello;";
$result = $this->pdo->query($sql);
return (bool) $result;
}
public function createTableIFNotExists() {
$sql = "CREATE TABLE IF NOT EXISTS `world` ( `what` VARCHAR(255) NOT NULL , PRIMARY KEY (`what`)) ENGINE = InnoDB;";
$result = $this->pdo->prepare($sql)->execute();
return (bool) $result;
}

public function hello($what = 'World')
public function insert($message)
{
$sql = "INSERT INTO hello VALUES (" . $this->pdo->quote($what) . ")";
$this->pdo->query($sql);
return "Hello $what";
$sql = "INSERT INTO world VALUES ('{$message}')";
$sth = $this->pdo->prepare($sql);
$result = $sth->execute();
return (bool) $result;
}


public function what()
public function getAll()
{
$sql = "SELECT what FROM hello";
$stmt = $this->pdo->query($sql);
return $stmt->fetchColumn();
$sql = "SELECT * FROM world";
$sth = $this->pdo->prepare($sql);
$sth->execute();
$result_array = $sth->fetchAll(PDO::FETCH_ASSOC);
return $result_array;
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ continuous integration with a PHP project.

Here is a sample status icon showing the state of the master branch.


[![Build Status](https://travis-ci.org/Robdebert/travisci-php-example-test.svg?branch=travistest)](https://travis-ci.org/Robdebert/travisci-php-example-test)

In order to run this project just fork it on github.com and then [enable](http://about.travis-ci.org/docs/user/getting-started/)
Expand Down
60 changes: 42 additions & 18 deletions Tests/HelloWorldTest.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,71 @@
<?php


class HelloWorldTest extends PHPUnit_Framework_TestCase
{
/**
* @var PDO
*/
private $pdo;
public $pdo = null;

public function setUp()
public function __construct()
{
$this->pdo = new PDO($GLOBALS['db_dsn'], $GLOBALS['db_username'], $GLOBALS['db_password']);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->query("CREATE TABLE hello (what VARCHAR(50) NOT NULL)");
$this->pdo = new PDO("mysql:host=localhost;dbname=hello", "root", "", array(
PDO::ATTR_PERSISTENT => true
));

$currentDir = __DIR__;
$baseDir = str_replace("\Tests", "", $currentDir);
$file = $baseDir."\HelloWorld.php";

include_once($file);
}

public function setup() {

$this->helloWorld = new HelloWorld($this->pdo);

}

public function tearDown()
{
$this->pdo->query("DROP TABLE hello");
unset($this->helloWorld);
}


public function testHelloWorld()
public function testDBCreate() {
$result = $this->helloWorld->createDBIFNotExists();
$this->assertTrue($result, true);
}

public function testTableCreate() {
$result = $this->helloWorld->createTableIFNotExists();
$this->assertTrue($result, true);
}



public function testInsert()
{
$helloWorld = new HelloWorld($this->pdo);

$this->assertEquals('Hello World', $helloWorld->hello());
$result = $this->helloWorld->insert("1. Versuch - ".date("d.m.Y H:i:s"));
$this->assertTrue($result);
}


public function testHello()
{
$helloWorld = new HelloWorld($this->pdo);

$this->assertEquals('Hello Bar', $helloWorld->hello('Bar'));
$results = $this->helloWorld->getAll();
$this->assertTrue(is_array($results), true); // https://phpunit.de/manual/current/en/appendixes.assertions.html
}


public function testWhat()
{
$helloWorld = new HelloWorld($this->pdo);

$this->assertFalse($helloWorld->what());

$helloWorld->hello('Bar');
$result = $this->helloWorld->insert("2. Versuch - ".date("d.m.Y H:i:s"));
$this->assertTrue($result);

$this->assertEquals('Bar', $helloWorld->what());
// $this->assertEquals('Bar', $this->helloWorld->getAll());
}
}

2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
print "HUHU";