Skip to content
This repository
Browse code

Fix #424

  • Loading branch information...
commit da3288c1cbf0f0ae00477a8d99f02ac852695f74 1 parent f9e3c77
William Durand willdurand authored

Showing 1 changed file with 0 additions and 147 deletions. Show diff stats Hide diff stats

  1. +0 147 test/README
147 test/README
... ... @@ -1,147 +0,0 @@
1   -= Running The Propel Unit Tests =
2   -
3   -== Background ==
4   -
5   -Propel uses [http://www.phpunit.de PHPUnit] to test the build and runtime frameworks.
6   -
7   -You can find the unit test classes and support files in the [browser:branches/1.6/test/testsuite] directory.
8   -
9   -== Install PHPUnit ==
10   -
11   -In order to run the tests, you must install PHPUnit:
12   -{{{
13   -> pear channel-discover pear.phpunit.de
14   -> pear install phpunit/PHPUnit
15   -}}}
16   -
17   -== Configure the Database to be Used in the Tests ==
18   -
19   -You must configure both the generator and the runtime connection settings.
20   -{{{
21   -// in test/fixtures/bookstore/build.properties
22   -propel.database = mysql
23   -propel.database.url = mysql:dbname=test
24   -propel.mysqlTableType = InnoDB
25   -propel.disableIdentifierQuoting=true
26   -# For MySQL or Oracle, you also need to specify username & password
27   -propel.database.user = myusername
28   -propel.database.password = p@ssw0rd
29   -}}}
30   -
31   -{{{
32   -// in test/fixtures/bookstore/runtime-conf.xml
33   -<datasource id="bookstore">
34   - <!-- the Propel adapter to use for this connection -->
35   - <adapter>mysql</adapter>
36   - <!-- Connection parameters. See PDO documentation for DSN format and available option constants. -->
37   - <connection>
38   - <classname>DebugPDO</classname>
39   - <dsn>mysql:dbname=test</dsn>
40   - <user>myusername</user>
41   - <password>p@ssw0rd</password>
42   - <options>
43   - <option id="ATTR_PERSISTENT">false</option>
44   - </options>
45   - <attributes>
46   - <!-- For MySQL, you should also turn on prepared statement emulation,
47   - as prepared statements support is buggy in mysql driver -->
48   - <option id="ATTR_EMULATE_PREPARES">true</option>
49   - </attributes>
50   - <settings>
51   - <!-- Set the character set for client connection -->
52   - <setting id="charset">utf8</setting>
53   - </settings>
54   - </connection>
55   -</datasource>
56   -}}}
57   -
58   -**Tip**: To run the unit tests for the namespace support in PHP 5.3, you must also configure the `fixtures/namespaced` project.
59   -**Tip**: To run the unit tests for the database schema support, you must also configure the `fixtures/schemas` project. This projects requires that your database supports schemas, and already contains the following schemas: `bookstore_schemas`, `contest`, and `second_hand_books`. Note that the user defined in `build.properties` and `runtime-conf.xml` must have access to these schemas.
60   -
61   -== Build the Propel Model and Initialize the Database ==
62   -
63   -{{{
64   -> cd /path/to/propel/test
65   -> ../generator/bin/propel-gen fixtures/bookstore main
66   -> mysqladmin create test
67   -> ../generator/bin/propel-gen fixtures/bookstore insert-sql
68   -}}}
69   -
70   -**Tip**: To run the unit tests for the namespace support in PHP 5.3, you must also build the `fixtures/namespaced` project.
71   -**Tip**: To run the unit tests for the database schema support, you must also build the `fixtures/schemas` project.
72   -
73   -If you test on MySQL, the following SQL script will create all the necessary test databases and grant access to the anonymous user, so the unit tests should pass without any special configuration:
74   -
75   -{{{
76   -#!sql
77   -CREATE DATABASE test;
78   -GRANT ALL ON test.* TO ''@'localhost';
79   -CREATE DATABASE bookstore_schemas;
80   -GRANT ALL ON bookstore_schemas.* TO ''@'localhost';
81   -CREATE DATABASE contest;
82   -GRANT ALL ON contest.* TO ''@'localhost';
83   -CREATE DATABASE second_hand_books;
84   -GRANT ALL ON second_hand_books.* TO ''@'localhost';
85   -CREATE DATABASE reverse_bookstore;
86   -GRANT ALL ON reverse_bookstore.* TO ''@'localhost';
87   -}}}
88   -
89   -== Run the Unit Tests ==
90   -
91   -Run all the unit tests at once using the `phpunit` command:
92   -{{{
93   -> cd /path/to/propel/test
94   -> phpunit testsuite
95   -}}}
96   -
97   -'''Warning''': The `testsuite/generator/builder/NamespaceTest.php` file uses PHP 5.3 namespaces, and therefore will create a parse error under PHP 5.2. To launch the unit test suite in a PHP 5.2 platform, simply delete this test file.
98   -
99   -To run a single test, go inside the unit test directory, and run the test using the command line. For example to run only GeneratedObjectTest:
100   -
101   -{{{
102   -> cd testsuite/generator/builder/om
103   -> phpunit GeneratedObjectTest
104   -}}}
105   -
106   -== How the Tests Work ==
107   -
108   -Every method in the test classes that begins with 'test' is run as a test case by PHPUnit. All tests are run in isolation; the `setUp()` method is called at the beginning of ''each'' test and the `tearDown()` method is called at the end.
109   -
110   -The [browser:branches/1.6/test/tools/helpers/bookstore/BookstoreTestBase.php BookstoreTestBase] class specifies `setUp()` and `tearDown()` methods which populate and depopulate, respectively, the database. This means that every unit test is run with a cleanly populated database. To see the sample data that is populated, take a look at the [browser:branches/1.6/test/tools/helpers/bookstore/BookstoreDataPopulator.php BookstoreDataPopulator] class. You can also add data to this class, if needed by your tests; however, proceed cautiously when changing existing data in there as there may be unit tests that depend on it. More typically, you can simply create the data you need from within your test method. It will be deleted by the `tearDown()` method, so no need to clean up after yourself.
111   -
112   -== Writing Tests ==
113   -
114   -If you've made a change to a template or to Propel behavior, the right thing to do is write a unit test that ensures that it works properly -- and continues to work in the future.
115   -
116   -Writing a unit test often means adding a method to one of the existing test classes. For example, let's test a feature in the Propel templates that supports saving of objects when only default values have been specified. Just add a `testSaveWithDefaultValues()` method to the [browser:branches/1.6/test/testsuite/generator/engine/builder/om/php5/GeneratedObjectTest.php GeneratedObjectTest] class, as follows:
117   -
118   -{{{
119   -#!php
120   -<?php
121   -/**
122   - * Test saving object when only default values are set.
123   - */
124   -public function testSaveWithDefaultValues() {
125   -
126   - // Relies on a default value of 'Penguin' specified in schema
127   - // for publisher.name col.
128   -
129   - $pub = new Publisher();
130   - $pub->setName('Penguin');
131   - // in the past this wouldn't have marked object as modified
132   - // since 'Penguin' is the value that's already set for that attrib
133   - $pub->save();
134   -
135   - // if getId() returns the new ID, then we know save() worked.
136   - $this->assertTrue($pub->getId() !== null, "Expect Publisher->save() to work with only default values.");
137   -}
138   -?>
139   -}}}
140   -
141   -Run the test again using the command line to check that it passes:
142   -
143   -{{{
144   -> phpunit GeneratedObjectTest
145   -}}}
146   -
147   -You can also write additional unit test classes to any of the directories in `test/testsuite/` (or add new directories if needed). The `phpunit` command will find these files automatically and run them.

0 comments on commit da3288c

Please sign in to comment.
Something went wrong with that request. Please try again.