├── .travis.yml
├── HelloWorld.php
├── README.md
├── Tests
├── HelloWorldTest.php
└── bootstrap.php
├── phpunit_mysql.xml
└── phpunit_pgsql.xml
/.travis.yml:
--------------------------------------------------------------------------------
1 | # see http://about.travis-ci.org/docs/user/languages/php/ for more hints
2 | language: php
3 |
4 | # list any PHP version you want to test against
5 | php:
6 | # using major version aliases
7 |
8 | # aliased to 5.2.17
9 | - 5.2
10 | # aliased to 5.3.29
11 | - 5.3
12 | # aliased to a recent 5.4.x version
13 | - 5.4
14 | # aliased to a recent 5.5.x version
15 | - 5.5
16 | # aliased to a recent 5.6.x version
17 | - 5.6
18 | # aliased to a recent 7.x version
19 | - 7.0
20 | # aliased to a recent hhvm version
21 | - hhvm
22 |
23 | # optionally specify a list of environments, for example to test different RDBMS
24 | env:
25 | - DB=mysql
26 | - DB=pgsql
27 |
28 | # optionally set up exclusions and allowed failures in the matrix
29 | matrix:
30 | exclude:
31 | - php: hhvm
32 | env: DB=pgsql # PDO driver for pgsql is unsupported by HHVM (3rd party install for support)
33 | allow_failures:
34 | - php: 7.0
35 | - php: hhvm
36 |
37 | # execute any number of scripts before the test run, custom env's are available as variables
38 | before_script:
39 | - if [[ "$DB" == "pgsql" ]]; then psql -c "DROP DATABASE IF EXISTS hello_world_test;" -U postgres; fi
40 | - if [[ "$DB" == "pgsql" ]]; then psql -c "create database hello_world_test;" -U postgres; fi
41 | - if [[ "$DB" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS hello_world_test;" -uroot; fi
42 |
43 | # omitting "script:" will default to phpunit
44 | # use the $DB env variable to determine the phpunit.xml to use
45 | script: phpunit --configuration phpunit_$DB.xml --coverage-text
46 |
47 | # configure notifications (email, IRC, campfire etc)
48 | notifications:
49 | irc: "irc.freenode.org#yourfavouriteroomfortravis"
50 |
--------------------------------------------------------------------------------
/HelloWorld.php:
--------------------------------------------------------------------------------
1 | pdo = $pdo;
13 | }
14 |
15 | public function hello($what = 'World')
16 | {
17 | $sql = "INSERT INTO hello VALUES (" . $this->pdo->quote($what) . ")";
18 | $this->pdo->query($sql);
19 | return "Hello $what";
20 | }
21 |
22 |
23 | public function what()
24 | {
25 | $sql = "SELECT what FROM hello";
26 | $stmt = $this->pdo->query($sql);
27 | return $stmt->fetchColumn();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Example PHP project
2 | ===================
3 |
4 | The purpose of this repository is to show how to use Travis CI to do
5 | continuous integration with a PHP project.
6 |
7 | Here is a sample status icon showing the state of the master branch.
8 |
9 | [](https://travis-ci.org/travis-ci-examples/php)
10 |
11 | In order to run this project just fork it on github.com and then [enable](http://about.travis-ci.org/docs/user/getting-started/)
12 | your fork on your [travis-ci profile](http://travis-ci.org/profile). Every push will then trigger a new build on Travis CI.
13 |
14 | (Don't forget to update the badge url in the README to point to your own travis project.)
15 |
--------------------------------------------------------------------------------
/Tests/HelloWorldTest.php:
--------------------------------------------------------------------------------
1 | pdo = new PDO($GLOBALS['db_dsn'], $GLOBALS['db_username'], $GLOBALS['db_password']);
13 | $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
14 | $this->pdo->query("CREATE TABLE hello (what VARCHAR(50) NOT NULL)");
15 | }
16 |
17 | public function tearDown()
18 | {
19 | $this->pdo->query("DROP TABLE hello");
20 | }
21 |
22 | public function testHelloWorld()
23 | {
24 | $helloWorld = new HelloWorld($this->pdo);
25 |
26 | $this->assertEquals('Hello World', $helloWorld->hello());
27 | }
28 |
29 | public function testHello()
30 | {
31 | $helloWorld = new HelloWorld($this->pdo);
32 |
33 | $this->assertEquals('Hello Bar', $helloWorld->hello('Bar'));
34 | }
35 |
36 | public function testWhat()
37 | {
38 | $helloWorld = new HelloWorld($this->pdo);
39 |
40 | $this->assertFalse($helloWorld->what());
41 |
42 | $helloWorld->hello('Bar');
43 |
44 | $this->assertEquals('Bar', $helloWorld->what());
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/Tests/bootstrap.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | ./Tests/
13 |
14 |
15 |
16 |
17 |
18 | ./
19 |
20 | ./Tests
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/phpunit_pgsql.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | ./Tests/
13 |
14 |
15 |
16 |
17 |
18 | ./
19 |
20 | ./Tests
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------