[5.6] Mysql integration test sample (#24672)
* Mysql integration test sample * Style CI
This commit is contained in:
parent
4e845b544d
commit
00f8e2baa1
|
@ -23,12 +23,14 @@ cache:
|
|||
services:
|
||||
- memcached
|
||||
- redis-server
|
||||
- mysql
|
||||
|
||||
before_install:
|
||||
- phpenv config-rm xdebug.ini || true
|
||||
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
|
||||
- printf "\n" | pecl install -f redis
|
||||
- travis_retry composer self-update
|
||||
- mysql -e 'CREATE DATABASE forge;'
|
||||
|
||||
install:
|
||||
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Illuminate\Tests\Integration\Database\Mysql;
|
||||
|
||||
use Orchestra\Testbench\TestCase;
|
||||
|
||||
class MysqlDatabaseTestCase extends TestCase
|
||||
{
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
$app['config']->set('app.debug', 'true');
|
||||
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'mysql',
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'forge',
|
||||
'prefix' => '',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Illuminate\Tests\Integration\Database\Mysql;
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class MysqlEloquentCollectionFreshTest extends MysqlDatabaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Schema::create('users', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->string('email');
|
||||
});
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Schema::drop('users');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_eloquent_collection_fresh()
|
||||
{
|
||||
User::insert([
|
||||
['email' => 'laravel@framework.com'],
|
||||
['email' => 'laravel@laravel.com'],
|
||||
]);
|
||||
|
||||
$collection = User::all();
|
||||
|
||||
User::whereKey($collection->pluck('id')->toArray())->delete();
|
||||
|
||||
$this->assertEmpty($collection->fresh()->filter());
|
||||
}
|
||||
}
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
}
|
Loading…
Reference in New Issue