|
| 1 | +# Configuration |
| 2 | + |
| 3 | +On this page you will learn how to configure: |
| 4 | + |
| 5 | +* [A production environment](#production) |
| 6 | +* [Caching](#caching) |
| 7 | +* [A development environment](#development) |
| 8 | +* [Unit testing](#unittesting) |
| 9 | + |
| 10 | +The configuration is entirely handled by the Laravel framework, if you encounter things that aren't covered on this page, visit the [Laravel configuration documentation](http://laravel.com/docs/4.2/configuration) or if that doesn't help you out, get in touch with us on [github](https://github.com/tdt). |
| 11 | + |
| 12 | +> Ideally, you don't change any files in the app/config directory, but copy them into a folder you create under app/config and then edit as you see fit. This allows for proper configuration management and will make your overall configuration flow alot easier. For more info on this, check out the [configuration documentation](http://four.laravel.com/docs/configuration). |
| 13 | +
|
| 14 | +The sections below are a summary of what the important parts of the configuration are. |
| 15 | + |
| 16 | +<a id='production' class='anchor'></a> |
| 17 | +## Production environment |
| 18 | + |
| 19 | +You'll find that configuring an application through the Laravel framework is really easy and straightforward. Head to the root of the application and go to <em>app/config</em>. The explanation below is the same for environment configurations such as production. Simply create a folder under <em>app/config</em> called production and copy the files you want to change. This should also be explained thoroughly in the [configuration documentation](http://four.laravel.com/docs/configuration) of Laravel. |
| 20 | + |
| 21 | +In the configuration folder you'll find a set of php files and folders that make up one or more configurations. The one that has to be changed is called <em>database.php</em> |
| 22 | + |
| 23 | +The codebase has been tested against a MySQL database, it uses the Eloquent abstraction layer, so any database supported by Eloquent you should be able to use. As an example we'll use MySQL as a default so change the default property to <em>mysql</em> and fill in the mysql entry in the connections array in the <em>database.php</em> file. There's no need to throw away the other connection options or change anything else. This should make your database.php file look something like the following. Note that the comments that are present from a default Laravel installation have been deleted for the sake of simplicity. |
| 24 | + |
| 25 | +<pre class='prettyprint'> |
| 26 | +return array( |
| 27 | + |
| 28 | + 'fetch' => PDO::FETCH_CLASS, |
| 29 | + |
| 30 | + 'default' => 'mysql', |
| 31 | + |
| 32 | + 'connections' => array( |
| 33 | + |
| 34 | + 'sqlite' => array( |
| 35 | + 'driver' => 'sqlite', |
| 36 | + 'database' => __DIR__.'/../database/production.sqlite', |
| 37 | + 'prefix' => '', |
| 38 | + ), |
| 39 | + |
| 40 | + 'mysql' => array( |
| 41 | + 'driver' => 'mysql', |
| 42 | + 'host' => 'localhost', |
| 43 | + 'database' => 'datatank_db', |
| 44 | + 'username' => 'foo', |
| 45 | + 'password' => 'bar', |
| 46 | + 'charset' => 'utf8', |
| 47 | + 'collation' => 'utf8_unicode_ci', |
| 48 | + 'prefix' => '', |
| 49 | + ), |
| 50 | + |
| 51 | + 'pgsql' => array( |
| 52 | + 'driver' => 'pgsql', |
| 53 | + 'host' => 'localhost', |
| 54 | + 'database' => 'database', |
| 55 | + 'username' => 'root', |
| 56 | + 'password' => '', |
| 57 | + 'charset' => 'utf8', |
| 58 | + 'prefix' => '', |
| 59 | + 'schema' => 'public', |
| 60 | + ), |
| 61 | + |
| 62 | + 'sqlsrv' => array( |
| 63 | + 'driver' => 'sqlsrv', |
| 64 | + 'host' => 'localhost', |
| 65 | + 'database' => 'database', |
| 66 | + 'username' => 'root', |
| 67 | + 'password' => '', |
| 68 | + 'prefix' => '', |
| 69 | + ), |
| 70 | + |
| 71 | + ), |
| 72 | + ... |
| 73 | +</pre> |
| 74 | + |
| 75 | +That's all there is to it! |
| 76 | + |
| 77 | +<a id='caching' class='anchor'></a> |
| 78 | +## Caching |
| 79 | + |
| 80 | +The data request made to The DataTank are cached using the [Laravel caching mechanism](http://four.laravel.com/docs/cache). For the datatank we use the Memcached to cache all of our requests and internal flags. So be sure to have it running and configured in a way that PHP can reach it. |
| 81 | + |
| 82 | +Head to the <em>cache.php</em> file and make sure that the default driver is set to memcached and fill in the necessary properties like so |
| 83 | + |
| 84 | +<pre class="prettyprint"> |
| 85 | +'enabled' => true, |
| 86 | + |
| 87 | +'driver' => 'memcached', |
| 88 | + |
| 89 | +... |
| 90 | + |
| 91 | +'memcached' => array( |
| 92 | + |
| 93 | + array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), |
| 94 | + |
| 95 | +), ... |
| 96 | +</pre> |
| 97 | + |
| 98 | +<a id='development' class='anchor'></a> |
| 99 | +## Development environment |
| 100 | + |
| 101 | +If you're planning on getting your hands dirty with The DataTank, you'll need to read up on how to configure environments in the [Laravel configuration documentation](http://four.laravel.com/docs/configuration#environment-configuration). In short, in order to load your database for development (e.g. localhost) only, you need to create a subfolder called <em>local</em> in the <em>app/config</em> folder, and make sure the environment is recognized by Laravel. This is done by adding your host name to the <em>$env</em> variable in the <em>bootstrap/start.php</em> file. Don't forget to add this file to the .gitignore file if you're using Git. |
| 102 | + |
| 103 | +<a id='unittesting' class='anchor'></a> |
| 104 | +## Unit testing |
| 105 | + |
| 106 | +If you want to run the unittests, to check if everything is still ok after adjustments or to test your own additional tests, go to the root of the application and perform the simple command: |
| 107 | + |
| 108 | + $ phpunit |
| 109 | + |
| 110 | +This will execute all of the tests located at the <em>app/tests</em> folder. |
| 111 | + |
| 112 | +If you've never performed the unit tests before, you will probably stumble upon a large series of errors. This is because the testing environment hasn't been configured yet. It is however a fairly simple thing to do. |
| 113 | + |
| 114 | +First you'll need to create a database that will be used by the unit tests. This can be configured in the <em>database.php</em> file inside the <em>app/config/testing</em> folder. Next you'll want to create the necessary tables in order to create a similar back-end as the application uses, in order to do this you'll need to perform the migration command, but with the testing environment as a parameter. |
| 115 | + |
| 116 | + $ php artisan migrate --env=testing |
| 117 | + |
| 118 | +Next, you'll have to migrate the extra package that we use for authentication purposes as well: |
| 119 | + |
| 120 | + $ php artisan migrate --env=testing --package=cartalyst/sentry |
| 121 | + |
| 122 | +After that, fill up the database with some basic users using our seeder: |
| 123 | + |
| 124 | + $ php artisan db:seed --env=testing |
| 125 | + |
| 126 | +That's it! You can perform the phpunit command now. |
0 commit comments