private function getGitVersion($fileOrDir) { $newestVersion = '0.0.0'; $currentDir = getcwd(); $gitCommand = 'git tag'; if (!Interaction::commandExist('git')) { return $newestVersion; } if (Str::endsWith($fileOrDir, 'php')) { $dir = dirname($fileOrDir); } else { $dir = $fileOrDir; } $dir = realpath($dir); chdir($dir); exec($gitCommand, $output); foreach ($output as $version) { if (version_compare($newestVersion, $version) === -1) { $newestVersion = $version; } } chdir($currentDir); return $newestVersion; }
/** * @dataProvider endsWithProvider * * @covers ::endsWith * * @param string $str * @param string $needle * @param bool $expected */ public function test_endsWith($str, $needle, $expected) { // When $got = Str::endsWith($str, $needle); // Then $this->assertSame($expected, $got); }
/** * Fix and rewrite table CREATE statement if needed. * * @param bool $addIfNotExists Set to true to add if not exists condition. * * @return string The table create statement. */ protected function fixTableCreateStatement($addIfNotExists = false) { $tableCS = $this->tableCS; if (!Str::endsWith(trim($this->tableCS), ';')) { $tableCS = trim($this->tableCS) . ";"; } $tableCS = preg_replace('/(AUTO_INCREMENT=)([0-9]+)/', '${1}1', $tableCS); if (!$addIfNotExists) { return $tableCS; } /* @noinspection SqlNoDataSourceInspection */ $tableCS = preg_replace('/CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $tableCS); return $tableCS; }