PHPackages                             wagnerpinheiro/sf-php-unit2plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. wagnerpinheiro/sf-php-unit2plugin

ActiveLibrary[Testing &amp; Quality](/categories/testing)

wagnerpinheiro/sf-php-unit2plugin
=================================

Unofficial git copy of symfony plugin sfPHPUnit2Plugin

011PHP

Since May 26Pushed 11y agoCompare

[ Source](https://github.com/wagnerpinheiro/sf-php-unit2plugin)[ Packagist](https://packagist.org/packages/wagnerpinheiro/sf-php-unit2plugin)[ RSS](/packages/wagnerpinheiro-sf-php-unit2plugin/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

sfPHPUnit2 plugin
=================

[](#sfphpunit2-plugin)

This repository is an unofficial copy of the svn version of this plugin on [symfony-project.org](http:www.symfony-project.org/plugins/sfPHPUnit2Plugin).

All credits go to the original author, Frank Stelzer.

---

The `sfPHPUnit2Plugin` is a symfony plugin that adds basic functionality for unit and functional testing with PHPUnit.

Symfony 1.x provides lime as default testing framework, but this does not match to every company's testing guidelines. This plugin provides several tasks for generating PHPUnit test cases and for executing them. It mimics the lime usage, so that switching from lime tests is quite easy. This plugin is optimized for sf 1.4 projects, but with some tricks it works also for sf 1.2.

The new plugin version supports generation and execution of selenium tests. Those tests are somehow an extension of functional tests but are handled independant from existing unit or functional tests. Developers who only want to run the normal native functional tests do not have to worry about the selenium handling.

Requirements
------------

[](#requirements)

- a symfony version greater equal 1.2 is required
- a special compatibility task has to be run for sf 1.2 projects (see phpunit:generate-compat below)
- the PHPUnit command-line test runner has to be available as `phpunit` in the command line (PHPUnit is **not** bundled with this plugin)
- PHPUnit 3.4 is required for running *all* tests, otherwise this plugin is independant to the PHPUnit version

Installation
------------

[](#installation)

This plugin is marked as **beta** currently. Therefore the stability option has to be added to the plugin installer

```
    $ ./symfony plugin:install --stability=beta sfPHPUnit2Plugin

```

Generate test cases
-------------------

[](#generate-test-cases)

### Unit tests

[](#unit-tests)

Generating a test case for a unit test:

```
    $ ./symfony phpunit:generate-unit

```

Creates a new file in *test/phpunit/unit/&lt;name&gt;Test.php*

An additional task for ***symfony 1.2*** projects has to be run which creates special bootstrap files

```
    $ ./symfony phpunit:generate-compat

```

This task has to be called at the very first time only.

### Functional tests

[](#functional-tests)

Generating a test case for a functional test:

```
    $ ./symfony phpunit:generate-functional

```

Creates a new file in *test/phpunit/functional/&lt;application&gt;/&lt;controller\_name&gt;ActionsTest.php*. This generation is not done automatically when a new module is generated and has to be called by hand currently.

### Selenium tests

[](#selenium-tests)

Generating a test case for a selenium test:

```
    $ ./symfony phpunit:generate-selenium

```

Creates a new file in *test/phpunit/selenium/&lt;application&gt;/&lt;controller\_name&gt;ActionsTest.php*. This generation is not done automatically when a new module is generated and has to be called by hand currently.

### Options

[](#options)

- **overwrite**: An existing test case is not overwritten by default. Overwritting is enabled with this option.
- **dir**: A subfolder the generated test case should be saved in.
- **template**: A template name to use for this test. Templates files should be placed in "data/sfPHPUnitPlugin/template//"
- **plugin**: A plugin name, without base dir (like sfPHPUnit instead of sfPHPUnitPlugin), to generate a test for this plugin.

### Examples

[](#examples)

```
    $ #test/phpunit/unit/somesubfolder/SomeToolsTest.php
    $ ./symfony phpunit:generate-unit --dir="somesubfolder" --overwrite --template="my_own_template" SomeTools

    $ #test/phpunit/functional/frontend/homeActionsTest.php
    $ ./symfony phpunit:generate-functional frontend home

    $ #test/phpunit/selenium/frontend/homeActionsTest.php
    $ ./symfony phpunit:generate-selenium frontend home

    $ #plugins/anExamplePlugin/test/phpunit/unit/SomeToolsTest.php
    $ ./symfony phpunit:generate-unit --plugin=anExample SomeTools

```

Usage
-----

[](#usage)

Usage
-----

[](#usage-1)

### Unit tests

[](#unit-tests-1)

The unit test given in the [official documenation](http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_unit_tests "Unit and Functional Testing") would look like this:

```
