<?php

namespace Concrete\Tests\File;

use Concrete\Tests\TestCase;

class ExecutableFilesTest extends TestCase
{
    public function testExecutableFiles()
    {
        if (DIRECTORY_SEPARATOR === '\\') {
            $this->markTestSkipped('Testing executable files requires a Posix environment');
        }
        $rc = -1;
        $output = [];
        @exec('find ' . escapeshellarg(DIR_BASE) . ' -type f -executable', $output, $rc);
        if ($rc !== 0) {
            $this->markTestSkipped('Failed to retrieve the list of executable files (' . implode("\n", $output) . ')');
        }
        $output = array_map(function ($file) { return substr($file, strlen(DIR_BASE) + 1); }, $output);
        $actual = array_filter($output, function ($file) {
            return strpos($file, '.git/') !== 0
                && strpos($file, 'concrete/vendor/') !== 0
                && strpos($file, 'packages/') !== 0
                && strpos($file, 'updates/') !== 0
            ;
        });
        sort($actual);
        $expected = [
            'concrete/bin/concrete',
            'concrete/bin/concrete5',
        ];
        $this->assertSame(
            $expected,
            $actual,
            'Checking that only selected files are executable'
        );
    }
}
