mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
made testing elegant.
This commit is contained in:
parent
ae7faf1e45
commit
f706ed75bf
@ -9,7 +9,7 @@ class TestExample extends PHPUnit_Framework_TestCase {
|
||||
*/
|
||||
public function testSomethingIsTrue()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<phpunit colors="true"
|
||||
bootstrap="phpunit.php"
|
||||
backupGlobals="false">
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix=".test.php">bundles/laravel-tests/cases</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
@ -46,6 +46,16 @@ IoC::singleton('task: session', function()
|
||||
return new Tasks\Session\Manager;
|
||||
});
|
||||
|
||||
/**
|
||||
* The "test" task is responsible for running the unit tests for
|
||||
* the application, bundles, and the core framework itself.
|
||||
* It provides a nice wrapper around PHPUnit.
|
||||
*/
|
||||
IoC::singleton('task: test', function()
|
||||
{
|
||||
return new Tasks\Test\Runner;
|
||||
});
|
||||
|
||||
/**
|
||||
* The bundle repository is responsible for communicating with
|
||||
* the Laravel bundle sources to get information regarding any
|
||||
@ -58,8 +68,8 @@ IoC::singleton('bundle.repository', function()
|
||||
|
||||
/**
|
||||
* The bundle publisher is responsible for publishing bundle
|
||||
* assets and tests to their correct directories within the
|
||||
* application, such as the web accessible directory.
|
||||
* assets to their correct directories within the install,
|
||||
* such as the web accessible directory.
|
||||
*/
|
||||
IoC::singleton('bundle.publisher', function()
|
||||
{
|
||||
|
@ -18,9 +18,7 @@ class Publisher {
|
||||
|
||||
$this->move($path.'public', PUBLIC_PATH.'bundles'.DS.$bundle);
|
||||
|
||||
$this->move($path.'tests', TESTS_PATH.'cases'.DS.'bundles'.DS.$bundle);
|
||||
|
||||
echo "Assets and tests published for bundle [$bundle].".PHP_EOL;
|
||||
echo "Assets published for bundle [$bundle].".PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
66
laravel/cli/tasks/test/runner.php
Normal file
66
laravel/cli/tasks/test/runner.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php namespace Laravel\CLI\Tasks\Test;
|
||||
|
||||
use Laravel\File;
|
||||
use Laravel\Bundle;
|
||||
use Laravel\CLI\Tasks\Task;
|
||||
|
||||
class Runner extends Task {
|
||||
|
||||
/**
|
||||
* Run all of the unit tests for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->bundle(array(DEFAULT_BUNDLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the tests for a given bundle.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @return void
|
||||
*/
|
||||
public function bundle($arguments = array())
|
||||
{
|
||||
// To run PHPUnit for the application, bundles, and the framework
|
||||
// from one task, we'll dynamically stub PHPUnit.xml files via
|
||||
// the task and point the test suite to the correct directory
|
||||
// based on what was requested.
|
||||
$this->stub(Bundle::path($arguments[0]).'tests');
|
||||
|
||||
$this->test();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run PHPUnit with the temporary XML configuration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function test()
|
||||
{
|
||||
// We'll simply fire off PHPUnit with the configuration switch
|
||||
// pointing to our temporary configuration file. This allows
|
||||
// us to flexibly run tests for any setup.
|
||||
passthru('phpunit -c '.BASE_PATH.'phpunit.xml');
|
||||
|
||||
@unlink(BASE_PATH.'phpunit.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a stub phpunit.xml file to the base directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return void
|
||||
*/
|
||||
protected function stub($directory)
|
||||
{
|
||||
$stub = File::get(SYS_PATH.'cli/tasks/test/stub.xml');
|
||||
|
||||
$stub = str_replace('{{directory}}', $directory, $stub);
|
||||
|
||||
File::put(BASE_PATH.'phpunit.xml', $stub);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
backupGlobals="false">
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix=".test.php">tests</directory>
|
||||
<directory suffix=".test.php">{{directory}}</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
0
tests/application/.gitignore
vendored
0
tests/application/.gitignore
vendored
0
tests/bundles/.gitignore
vendored
0
tests/bundles/.gitignore
vendored
Loading…
x
Reference in New Issue
Block a user