serbanghita/Mobile-Detect — pull request #137 by nicktacular (2013-07-29 19:45:06+00:00)
Title: code style, more tests, test detail, and small other things

A bunch of commits. Here's a summary.

1. Added PHPUnit as a composer dependency and committed the `composer.lock`.
2. Added `getHttpHeader` method to get headers by their HTTP name, such as `getHttpHeader('User-Agent')` or with the PHP flavor, like `getHttpHeader('HTTP_USER_AGENT')`. Also returns `null` so it shortens code where you use it and need to test `isset($arr['key']) ? $arr['key'] : null`.
3. The constructor now uses dependency injection to more easily test, rather than immediately grabbing stuff from `_SERVER` when you construct. Backwards compatible. Nothing needs to be passed, in which case it will still use `_SERVER` if that's what you indended.
4. Some style stuff, like adding phpdoc comments everywhere, utilizing named constants everywhere, and throwing a `BadMethodCallException` in `__call` if the method doesn't start with `is`. The motivation here is that a typo like `isMoblie` will return `false` always, but sometimes that will give you a false positive on a test. Better get an exception.
5. The file `UA_List.inc.php` now returns the array so it's easier to use and no need to know what the global variable is called in that file. Similarly, modified the `VendorsTest.php` to make sure it works.
6. Added a `UserAgentsTest.php` which is similar to `VendorsTest.php` but has a few changes/modifications/improvements:
* Gives you more detail about your tests. Tells you it ran 500 tests which means that it tested 500 user agents. Also, tells you when tests are incomplete because the `UA_List.inc.php` file isn't complete with information. Gives you a sense of how complete your tests are.
* Converts `UA_List.inc.php` to a JSON file called `ualist.json` for clarity. I would prefer a JSON format for the test data, if that's ok with you.
* Caught a potential miss in the `VendorsTest.php` whereby an array item in the `UA_List.inc.php` was missing `isMobile` and `isTablet` properties. So this new test does some more tests on the data and warns you when there's something missing.
7. Added more tests to `BasicsTest.php`. Will keep adding more here as I keep working on this.
8. Modified `setHttpHeaders` to be consistent. The method would check for `HTTP_` prefix from `$this->httpHeaders` but wouldn't do that check for when passing as a parameter. I fixed this and updated the tests.