Don't break people's code just because they don't have Composer

This commit is contained in:
Christian Bläul
2018-02-21 21:48:04 +01:00
committed by Fonata
parent 68239d6859
commit c9e7997643
3 changed files with 36 additions and 10 deletions

View File

@@ -1,20 +1,17 @@
<?php <?php
// This file should not be used at all! It purely exists to reduce the // This file should not be used at all! Instead, please use Composer's autoload.
// maintenance burden for existing code using this repo. // It purely exists to reduce the maintenance burden for existing code using
// this repository.
// Check if people used Composer to include this project in theirs // Check if people used Composer to include this project in theirs
if (!file_exists(__DIR__ . '/vendor/autoload.php')) { if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
die( require __DIR__ . '/src/extensions/DatatypeTrait.php';
"Please run `composer dump-autoload` to build the autoloader.\n\n" . require __DIR__ . '/src/Csv.php';
"Actually, you should consider not including/requiring this file \n" . } else {
" " . __FILE__ . "\n" . require __DIR__ . '/vendor/autoload.php';
"Just run `composer require parsecsv/php-parsecsv` and look at the \n" .
"'examples' directory of this repository."
);
} }
require __DIR__ . '/vendor/autoload.php';
// This wrapper class should not be used by new projects. Please look at the // This wrapper class should not be used by new projects. Please look at the
// examples to find the up-to-date way of using this repo. // examples to find the up-to-date way of using this repo.

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace ParseCsv; namespace ParseCsv;
use ParseCsv\extensions\DatatypeTrait; use ParseCsv\extensions\DatatypeTrait;

View File

@@ -0,0 +1,28 @@
<?php
namespace ParseCsv\tests\methods;
use PHPUnit\Framework\TestCase;
class OldRequireTest extends TestCase {
protected function setUp() {
rename('vendor/autoload.php', '__autoload');
}
protected function tearDown() {
rename('__autoload', 'vendor/autoload.php');
}
/**
* @runInSeparateProcess because download.php uses header()
*/
public function testOldLibWithoutComposer() {
file_put_contents('__eval.php', '<?php require "parsecsv.lib.php"; new \ParseCsv\Csv;');
exec("php __eval.php", $output, $return_var);
unlink('__eval.php');
$this->assertEquals($output, []);
$this->assertEquals(0, $return_var);
}
}