<commit_before><?php

namespace Spatie\Backup\Test\Integration;

use Carbon\Carbon;
use Illuminate\Support\Facades\Artisan;

class BackupCommandTest extends TestCase
{
    /** @var \Carbon\Carbon */
    protected $date;

    /** @var string */
    protected $expectedZipPath;

    public function setUp()
    {
        parent::setUp();

        $this->date = Carbon::create('2016', 1, 1, 21, 1, 1);

        Carbon::setTestNow($this->date);

        $this->expectedZipPath = 'mysite.com/2016-01-01-21-01-01.zip';

        $this->app['config']->set('laravel-backup.backup.destination.disks', [
            'local',
            'secondLocal',
        ]);
    }

    /** @test */
    public function it_can_backup_only_the_files()
    {
        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_can_backup_using_a_custom_filename()
    {
        $this->date = Carbon::create('2016', 1, 1, 9, 1, 1);

        Carbon::setTestNow($this->date);

        $this->app['config']->set('laravel-backup.backup.destination.filename_prefix', 'custom_name_');

        $this->expectedZipPath = 'mysite.com/custom_name_2016-01-01-09-01-01.zip';

        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }
    
    /** @test */
    public function it_can_backup_using_a_custom_filename_as_option()
    {
        $this->date = Carbon::create('2016', 1, 1, 9, 1, 1);

        Carbon::setTestNow($this->date);
        
        $filename = 'testing-filename.zip';
        
        $this->expectedZipPath = 'mysite.com/'.$filename;
        
        $resultCode = Artisan::call('backup:run', ['--only-files' => true, '--filename' => $filename]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }
    

    /** @test */
    public function it_can_backup_to_a_specific_disk()
    {
        $resultCode = Artisan::call('backup:run', [
            '--only-files'   => true,
            '--only-to-disk' => 'secondLocal',
        ]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'local');
        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_can_backup_twice_a_day_at_same_time_in_12h_clock()
    {
        // first backup
        $this->date = Carbon::create('2016', 1, 1, 9, 1, 1);

        Carbon::setTestNow($this->date);

        $this->expectedZipPath = 'mysite.com/2016-01-01-09-01-01.zip';

        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');

        // second backup
        $this->date = Carbon::create('2016', 1, 1, 21, 1, 1);

        Carbon::setTestNow($this->date);

        $this->expectedZipPath = 'mysite.com/2016-01-01-21-01-01.zip';

        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_will_fail_when_try_to_backup_only_the_files_and_only_the_db()
    {
        $resultCode = Artisan::call('backup:run', [
            '--only-files' => true,
            '--only-db'    => true,
        ]);

        $this->assertEquals(-1, $resultCode);

        $this->seeInConsoleOutput('Cannot use `only-db` and `only-files` together.');

        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'local');
        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_will_fail_when_trying_to_backup_a_non_existing_database()
    {
        //since our test environment did not set up a db, this will fail
        Artisan::call('backup:run', [
            '--only-db' => true,
        ]);

        $this->seeInConsoleOutput('Backup failed');
    }

    /** @test */
    public function it_will_fail_when_trying_to_backup_to_an_non_existing_diskname()
    {
        $resultCode = Artisan::call('backup:run', [
            '--only-to-disk' => 'non existing disk',
        ]);

        $this->assertEquals(-1, $resultCode);

        $this->seeInConsoleOutput('There is not backup destination with a disk named');

        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'local');
        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_will_fail_when_there_are_no_files_to_be_backed_up()
    {
        $this->app['config']->set('laravel-backup.backup.source.files.include', []);
        $this->app['config']->set('laravel-backup.backup.source.databases', []);

        Artisan::call('backup:run');

        $this->seeInConsoleOutput('There are no files to be backed up');
    }
}
<commit_msg>Apply fixes from StyleCI (#349)<commit_after><?php

namespace Spatie\Backup\Test\Integration;

use Carbon\Carbon;
use Illuminate\Support\Facades\Artisan;

class BackupCommandTest extends TestCase
{
    /** @var \Carbon\Carbon */
    protected $date;

    /** @var string */
    protected $expectedZipPath;

    public function setUp()
    {
        parent::setUp();

        $this->date = Carbon::create('2016', 1, 1, 21, 1, 1);

        Carbon::setTestNow($this->date);

        $this->expectedZipPath = 'mysite.com/2016-01-01-21-01-01.zip';

        $this->app['config']->set('laravel-backup.backup.destination.disks', [
            'local',
            'secondLocal',
        ]);
    }

    /** @test */
    public function it_can_backup_only_the_files()
    {
        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_can_backup_using_a_custom_filename()
    {
        $this->date = Carbon::create('2016', 1, 1, 9, 1, 1);

        Carbon::setTestNow($this->date);

        $this->app['config']->set('laravel-backup.backup.destination.filename_prefix', 'custom_name_');

        $this->expectedZipPath = 'mysite.com/custom_name_2016-01-01-09-01-01.zip';

        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_can_backup_using_a_custom_filename_as_option()
    {
        $this->date = Carbon::create('2016', 1, 1, 9, 1, 1);

        Carbon::setTestNow($this->date);

        $filename = 'testing-filename.zip';

        $this->expectedZipPath = 'mysite.com/'.$filename;

        $resultCode = Artisan::call('backup:run', ['--only-files' => true, '--filename' => $filename]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_can_backup_to_a_specific_disk()
    {
        $resultCode = Artisan::call('backup:run', [
            '--only-files'   => true,
            '--only-to-disk' => 'secondLocal',
        ]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'local');
        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_can_backup_twice_a_day_at_same_time_in_12h_clock()
    {
        // first backup
        $this->date = Carbon::create('2016', 1, 1, 9, 1, 1);

        Carbon::setTestNow($this->date);

        $this->expectedZipPath = 'mysite.com/2016-01-01-09-01-01.zip';

        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');

        // second backup
        $this->date = Carbon::create('2016', 1, 1, 21, 1, 1);

        Carbon::setTestNow($this->date);

        $this->expectedZipPath = 'mysite.com/2016-01-01-21-01-01.zip';

        $resultCode = Artisan::call('backup:run', ['--only-files' => true]);

        $this->assertEquals(0, $resultCode);

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'local');

        $this->assertFileExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_will_fail_when_try_to_backup_only_the_files_and_only_the_db()
    {
        $resultCode = Artisan::call('backup:run', [
            '--only-files' => true,
            '--only-db'    => true,
        ]);

        $this->assertEquals(-1, $resultCode);

        $this->seeInConsoleOutput('Cannot use `only-db` and `only-files` together.');

        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'local');
        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_will_fail_when_trying_to_backup_a_non_existing_database()
    {
        //since our test environment did not set up a db, this will fail
        Artisan::call('backup:run', [
            '--only-db' => true,
        ]);

        $this->seeInConsoleOutput('Backup failed');
    }

    /** @test */
    public function it_will_fail_when_trying_to_backup_to_an_non_existing_diskname()
    {
        $resultCode = Artisan::call('backup:run', [
            '--only-to-disk' => 'non existing disk',
        ]);

        $this->assertEquals(-1, $resultCode);

        $this->seeInConsoleOutput('There is not backup destination with a disk named');

        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'local');
        $this->assertFileNotExistsOnDisk($this->expectedZipPath, 'secondLocal');
    }

    /** @test */
    public function it_will_fail_when_there_are_no_files_to_be_backed_up()
    {
        $this->app['config']->set('laravel-backup.backup.source.files.include', []);
        $this->app['config']->set('laravel-backup.backup.source.databases', []);

        Artisan::call('backup:run');

        $this->seeInConsoleOutput('There are no files to be backed up');
    }
}

{'fraction_non_alphanumeric': 0.1698755261036984, 'fraction_numerical': 0.02050685054177487, 'mean_word_length': 2.910364145658263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 161, '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': '5550214', 'n_tokens_mistral': 3780, 'n_tokens_neox': 3474, 'n_words': 508}