<commit_before><?php

namespace Canvas\Tests;

use Dotenv\Dotenv;
use Canvas\Entities\Tag;
use Canvas\Entities\Post;
use Canvas\Tests\Unit\User;
use Canvas\CanvasServiceProvider;
use Illuminate\Database\Schema\Blueprint;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
    /**
     * @var Post
     */
    protected $testPost;

    /**
     * @var Tag
     */
    protected $testTag;

    /**
     * @var User
     */
    protected $testUser;

    /**
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        $this->setUpDatabase($this->app);

        $this->testUser = User::first();
        $this->testPost = app(Post::class)->find(1);
        $this->testTag = app(Tag::class)->find(1);
    }

    /**
     * @param \Illuminate\Foundation\Application $app
     *
     * @return array
     */
    protected function getPackageProviders($app)
    {
        return [
            CanvasServiceProvider::class,
        ];
    }

    /**
     * Set up the environment.
     *
     * @param \Illuminate\Foundation\Application $app
     */
    protected function getEnvironmentSetUp($app)
    {
        // If we're not in TravisCI, load our local .env file
        if (empty(getenv('CI'))) {
            $envPath = realpath(__DIR__.'/..');
            if (! file_exists($envPath)) {
                $dotenv = new Dotenv($envPath);
                $dotenv->load();
            }
        }

        $app['config']->set('database.default', 'sqlite');
        $app['config']->set('database.connections.sqlite', [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ]);

        $app['config']->set('view.paths', [__DIR__.'/resources/views']);

        // Use test User model for users provider
        $app['config']->set('auth.providers.users.model', User::class);
    }

    /**
     * Set up the database.
     *
     * @param \Illuminate\Foundation\Application $app
     */
    protected function setUpDatabase($app)
    {
        $this->artisan('migrate:fresh');

        $app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email');
            $table->softDeletes();
        });

        include_once __DIR__.'/../database/migrations/2018_10_12_000000_create_posts_table.php';
        include_once __DIR__.'/../database/migrations/2018_10_12_000000_create_tags_table.php';
        include_once __DIR__.'/../database/migrations/2018_10_13_000000_create_taggables_table.php';

        (new \CreatePostsTable())->up();
        (new \CreateTagsTable())->up();
        (new \CreateTaggablesTable())->up();

        User::create(['email' => '<EMAIL>']);
        Post::create(['title' => 'post title', 'summary' => 'post summary', 'body' => 'post body', 'user_id' => 1]);
        Tag::create(['name' => 'tag name']);
    }

    /**
     * Refresh the testUser.
     */
    public function refreshTestUser()
    {
        $this->testUser = $this->testUser->fresh();
    }
<commit_msg>Simplify the database setup<commit_after><?php

namespace Canvas\Tests;

use Dotenv\Dotenv;
use Canvas\Entities\Tag;
use Canvas\Entities\Post;
use Canvas\Tests\Unit\User;
use Canvas\CanvasServiceProvider;
use Illuminate\Database\Schema\Blueprint;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
    /**
     * @var Post
     */
    protected $testPost;

    /**
     * @var Tag
     */
    protected $testTag;

    /**
     * @var User
     */
    protected $testUser;

    /**
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        $this->setUpDatabase($this->app);

        $this->testUser = User::first();
        $this->testPost = app(Post::class)->find(1);
        $this->testTag = app(Tag::class)->find(1);
    }

    /**
     * @param \Illuminate\Foundation\Application $app
     *
     * @return array
     */
    protected function getPackageProviders($app)
    {
        return [
            CanvasServiceProvider::class,
        ];
    }

    /**
     * Set up the environment.
     *
     * @param \Illuminate\Foundation\Application $app
     */
    protected function getEnvironmentSetUp($app)
    {
        // If we're not in TravisCI, load our local .env file
        if (empty(getenv('CI'))) {
            $envPath = realpath(__DIR__.'/..');
            if (! file_exists($envPath)) {
                $dotenv = new Dotenv($envPath);
                $dotenv->load();
            }
        }

        $app['config']->set('database.default', 'sqlite');
        $app['config']->set('database.connections.sqlite', [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ]);

        $app['config']->set('view.paths', [__DIR__.'/resources/views']);

        // Use test User model for users provider
        $app['config']->set('auth.providers.users.model', User::class);
    }

    /**
     * Set up the database.
     *
     * @param \Illuminate\Foundation\Application $app
     */
    protected function setUpDatabase($app)
    {
        $this->artisan('migrate:fresh');

        $app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email');
            $table->softDeletes();
        });

        $this->loadMigrationsFrom(__DIR__.'/database/migrations');

        User::create(['email' => '<EMAIL>']);
        Post::create(['title' => 'post title', 'summary' => 'post summary', 'body' => 'post body', 'user_id' => 1]);
        Tag::create(['name' => 'tag name']);
    }

    /**
     * Refresh the testUser.
     */
    public function refreshTestUser()
    {
        $this->testUser = $this->testUser->fresh();
    }

{'fraction_non_alphanumeric': 0.1690952219586581, 'fraction_numerical': 0.008132836326668925, 'mean_word_length': 2.173655913978495, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7177165', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1765, 'n_words': 316}