Skip to content

Commit

Permalink
Improving tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaposa committed Sep 4, 2015
1 parent c86726a commit 8426720
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 250 deletions.
16 changes: 5 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
composer.lock

test/TestConfig.php
nbproject
.project
composer.lock
vendor
phpunit.xml
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# MobileDetectModule

MobileDetectModule is a ZF2 module which facilitates integration of a PHP MobileDetect class
[![Build Status](https://travis-ci.org/nikolaposa/MobileDetectModule.svg?branch=master)](https://travis-ci.org/nikolaposa/MobileDetectModule)

MobileDetectModule is a ZF2 module which facilitates integration of a PHP MobileDetect class
([http://mobiledetect.net](http://mobiledetect.net)).

## Installation
Expand All @@ -11,7 +13,7 @@ Add this project into your composer.json:

```json
"require": {
"nikolaposa/mobile-detect-module": "dev-master"
"nikolaposa/mobile-detect-module": "~1.0"
}
```

Expand All @@ -20,10 +22,10 @@ Tell composer to download MobileDetectModule by running update command:
```bash
$ php composer.phar update
```

For more information about composer itself, please refer to [getcomposer.org](http://getcomposer.org/).

**Heads up! Composer autoloader must be utilized in your application so that MobileDetect dependency
**Heads up! Composer autoloader must be utilized in your application so that MobileDetect dependency
of this module can be loaded properly.**

### Enable the module in your `application.config.php`:
Expand All @@ -43,12 +45,12 @@ return array(

* Factory for creating MobileDetect service
* View helper and controller plugin for providing easier access to the MobileDetect service

## Usage

### MobileDetect service

The actual `Mobile_Detect` class instance will be available under the `MobileDetect` service. Refer to
The actual `Mobile_Detect` class instance will be available under the `MobileDetect` service. Refer to
the [Mobile Detect](http://mobiledetect.net/) project documenation for more information about its features.
```php
$mobileDetect = $serviceLocator->get('MobileDetect'); //`Mobile_Detect` class instance
Expand All @@ -59,15 +61,15 @@ if ($mobileDetect->isMobile()) {

### View helper

View helper - `mobileDetect` is available for providing access to the MobileDetect service on the
View helper - `mobileDetect` is available for providing access to the MobileDetect service on the
view layer:
```php
echo $this->mobileDetect()->version('Android');
```

### Controller plugin

Controller plugin - `mobileDetect` is available for providing access to the MobileDetect service on
Controller plugin - `mobileDetect` is available for providing access to the MobileDetect service on
the controller layer:
```php
if ($this->mobileDetect()->isTablet()) {
Expand Down
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@
"mobiledetect/mobiledetectlib": "2.*"
},
"require-dev": {
"zendframework/zend-loader": "2.*"
"zendframework/zend-config": "2.*",
"zendframework/zend-loader": "2.*",
"zendframework/zend-stdlib": "2.*",
"zendframework/zend-serializer": "2.*",
"zendframework/zend-log": "2.*",
"zendframework/zend-i18n": "2.*"
},
"autoload": {
"psr-0": {
"MobileDetectModule": "src/",
"MobileDetectModuleTest": "test/"
"MobileDetectModule": "src/"
},
"classmap": [
"./"
"src/"
]
},
"autoload-dev": {
"psr-0": { "MobileDetectModuleTest": "tests/" }
}
}
7 changes: 7 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<phpunit bootstrap="./tests/Bootstrap.php" colors="true">
<testsuites>
<testsuite name="MobileDetectModule Module Tests">
<directory>./tests/MobileDetectModuleTest</directory>
</testsuite>
</testsuites>
</phpunit>
91 changes: 0 additions & 91 deletions test/Bootstrap.php

This file was deleted.

8 changes: 0 additions & 8 deletions test/TestConfig.php.dist

This file was deleted.

7 changes: 0 additions & 7 deletions test/phpunit.xml

This file was deleted.

1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestConfig.php
16 changes: 16 additions & 0 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use MobileDetectModuleTest\Util\ServiceManagerFactory;

error_reporting(E_ALL | E_STRICT);
chdir(__DIR__);

require __DIR__ . '/../vendor/autoload.php';

if (file_exists(__DIR__ . '/TestConfig.php')) {
$config = include __DIR__ . '/TestConfig.php';
} else {
$config = include __DIR__ . '/TestConfig.php.dist';
}

ServiceManagerFactory::setConfig($config);
ServiceManagerFactory::getServiceManager();
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?php
/**
* This file is part of the MobileDetectModule package.
*
* Copyright (c) Nikola Posa <posa.nikola@gmail.com>
*
* For full copyright and license information, please refer to the LICENSE file,
* located at the package root folder.
*/

namespace MobileDetectModuleTest\Mvc\Controller\Plugin;

use PHPUnit_Framework_TestCase;
use MobileDetectModule\Mvc\Controller\Plugin\MobileDetect as MobileDetectPlugin;

/**
* @author Nikola Posa <posa.nikola@gmail.com>
*/
class MobileDetectTest extends PHPUnit_Framework_TestCase
{
public function testInvokationReturnsMobileDetectInstance()
{
$mobileDetect = $this->getMock('Detection\MobileDetect', array(), array(), '', false);

$plugin = new MobileDetectPlugin($mobileDetect);

$this->assertSame($mobileDetect, $plugin());
}
}
<?php
/**
* This file is part of the MobileDetectModule package.
*
* Copyright (c) Nikola Posa <posa.nikola@gmail.com>
*
* For full copyright and license information, please refer to the LICENSE file,
* located at the package root folder.
*/

namespace MobileDetectModuleTest\Mvc\Controller\Plugin;

use PHPUnit_Framework_TestCase;
use MobileDetectModule\Mvc\Controller\Plugin\MobileDetect as MobileDetectPlugin;

/**
* @author Nikola Posa <posa.nikola@gmail.com>
*/
class MobileDetectTest extends PHPUnit_Framework_TestCase
{
public function testInvokationReturnsMobileDetectInstance()
{
$mobileDetect = $this->getMock('Detection\MobileDetect', array(), array(), '', false);

$plugin = new MobileDetectPlugin($mobileDetect);

$this->assertSame($mobileDetect, $plugin());
}
}
Loading

0 comments on commit 8426720

Please sign in to comment.