Skip to content

Commit e8eabd6

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 60c0005 + ba42728 commit e8eabd6

File tree

7 files changed

+132
-8
lines changed

7 files changed

+132
-8
lines changed

.appveyor/composer.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@php "%~dp0composer.phar" %*

appveyor.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
build: false
2+
clone_folder: c:\projects\maker-bundle
3+
4+
cache:
5+
- composer.phar
6+
- .phpunit -> phpunit
7+
8+
init:
9+
- SET PATH=c:\php;%PATH%
10+
11+
install:
12+
- mkdir c:\php && cd c:\php
13+
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php-7.1.3-Win32-VC14-x86.zip
14+
- 7z x php-7.1.3-Win32-VC14-x86.zip -y >nul
15+
- cd ext
16+
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_apcu-5.1.8-7.1-ts-vc14-x86.zip
17+
- 7z x php_apcu-5.1.8-7.1-ts-vc14-x86.zip -y >nul
18+
- cd ..
19+
- copy /Y php.ini-development php.ini-min
20+
- echo memory_limit=-1 >> php.ini-min
21+
- echo serialize_precision=14 >> php.ini-min
22+
- echo max_execution_time=1200 >> php.ini-min
23+
- echo date.timezone="America/Los_Angeles" >> php.ini-min
24+
- echo extension_dir=ext >> php.ini-min
25+
- copy /Y php.ini-min php.ini-max
26+
- echo zend_extension=php_opcache.dll >> php.ini-max
27+
- echo opcache.enable_cli=1 >> php.ini-max
28+
- echo extension=php_openssl.dll >> php.ini-max
29+
- echo extension=php_apcu.dll >> php.ini-max
30+
- echo apc.enable_cli=1 >> php.ini-max
31+
- echo extension=php_intl.dll >> php.ini-max
32+
- echo extension=php_mbstring.dll >> php.ini-max
33+
- echo extension=php_fileinfo.dll >> php.ini-max
34+
- echo extension=php_pdo_sqlite.dll >> php.ini-max
35+
- echo extension=php_curl.dll >> php.ini-max
36+
- copy /Y php.ini-max php.ini
37+
38+
- cd c:\php
39+
- IF NOT EXIST composer.phar (appveyor DownloadFile https://getcomposer.org/download/1.6.3/composer.phar)
40+
- php composer.phar self-update
41+
# copy instead of using echo because appveyor does not allow "%s" characters
42+
- copy /Y c:\projects\maker-bundle\.appveyor\composer.bat composer.bat
43+
44+
- cd c:\projects\maker-bundle
45+
- php -dmemory_limit=-1 c:\php\composer.phar install --no-progress --no-suggest --ansi
46+
- composer dump-autoload
47+
- ./vendor/bin/simple-phpunit install
48+
49+
test_script:
50+
- ./vendor/bin/simple-phpunit

src/FileManager.php

+33-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FileManager
3333
public function __construct(Filesystem $fs, string $rootDirectory)
3434
{
3535
$this->fs = $fs;
36-
$this->rootDirectory = rtrim($this->realpath($rootDirectory).'/');
36+
$this->rootDirectory = rtrim($this->realpath($this->normalizeSlashes($rootDirectory)), '/');
3737
}
3838

3939
public function setIO(SymfonyStyle $io)
@@ -61,8 +61,19 @@ public function fileExists($path): bool
6161
return file_exists($this->absolutizePath($path));
6262
}
6363

64+
/**
65+
* Attempts to make the path relative to the root directory.
66+
*
67+
* @param string $absolutePath
68+
*
69+
* @return string
70+
*
71+
* @throws \Exception
72+
*/
6473
public function relativizePath($absolutePath): string
6574
{
75+
$absolutePath = $this->normalizeSlashes($absolutePath);
76+
6677
// see if the path is even in the root
6778
if (false === strpos($absolutePath, $this->rootDirectory)) {
6879
return $absolutePath;
@@ -78,6 +89,15 @@ public function relativizePath($absolutePath): string
7889
return is_dir($absolutePath) ? rtrim($relativePath, '/').'/' : $relativePath;
7990
}
8091

92+
/**
93+
* Returns the relative path to where a new class should live.
94+
*
95+
* @param string $className
96+
*
97+
* @return null|string
98+
*
99+
* @throws \Exception
100+
*/
81101
public function getPathForFutureClass(string $className)
82102
{
83103
// lookup is obviously modeled off of Composer's autoload logic
@@ -138,12 +158,17 @@ private function getClassLoader(): ClassLoader
138158
return self::$classLoader;
139159
}
140160

141-
private function absolutizePath($path): string
161+
public function absolutizePath($path): string
142162
{
143163
if (0 === strpos($path, '/')) {
144164
return $path;
145165
}
146166

167+
// support windows drive paths: C:\
168+
if (1 === strpos($path, ':\\')) {
169+
return $path;
170+
}
171+
147172
return sprintf('%s/%s', $this->rootDirectory, $path);
148173
}
149174

@@ -159,6 +184,7 @@ private function realPath($absolutePath): string
159184
$finalParts = [];
160185
$currentIndex = -1;
161186

187+
$absolutePath = $this->normalizeSlashes($absolutePath);
162188
foreach (explode('/', $absolutePath) as $pathPart) {
163189
if ('..' === $pathPart) {
164190
// we need to remove the previous entry
@@ -184,4 +210,9 @@ private function realPath($absolutePath): string
184210

185211
return $finalPath;
186212
}
213+
214+
private function normalizeSlashes(string $path)
215+
{
216+
return str_replace('\\', '/', $path);
217+
}
187218
}

src/Test/MakerTestCase.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class MakerTestCase extends TestCase
3434
public static function setupPaths()
3535
{
3636
self::$currentRootDir = __DIR__.'/../../tests/tmp/current_project';
37-
self::$flexProjectPath = __DIR__.'/../../tests/tmp/template_project';
3837
self::$fixturesCachePath = __DIR__.'/../../tests/tmp/cache';
38+
self::$flexProjectPath = self::$fixturesCachePath.'/flex_project';
3939
}
4040

4141
protected function executeMakerCommand(MakerTestDetails $testDetails)
@@ -133,7 +133,7 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
133133
// execute the tests that were moved into the project!
134134
$process = $this->createProcess(
135135
// using OUR simple-phpunit for speed (to avoid downloading more deps)
136-
'../../../vendor/bin/simple-phpunit',
136+
__DIR__.'/../../vendor/bin/simple-phpunit',
137137
self::$currentRootDir
138138
);
139139
$process->run();
@@ -155,7 +155,11 @@ protected function assertContainsCount(string $needle, string $haystack, int $co
155155

156156
private function buildFlexProject()
157157
{
158-
$process = $this->createProcess('composer create-project symfony/skeleton template_project', dirname(self::$flexProjectPath));
158+
$targetFlexDir = dirname(self::$flexProjectPath);
159+
if (!file_exists($targetFlexDir)) {
160+
self::$fs->mkdir($targetFlexDir);
161+
}
162+
$process = $this->createProcess('composer create-project symfony/skeleton flex_project', $targetFlexDir);
159163
$this->runProcess($process);
160164

161165
// processes any changes needed to the Flex project
@@ -168,7 +172,7 @@ private function buildFlexProject()
168172
[
169173
'filename' => 'composer.json',
170174
'find' => '"App\\\Tests\\\": "tests/"',
171-
'replace' => sprintf('"App\\\Tests\\\": "tests/",'."\n".' "Symfony\\\Bundle\\\MakerBundle\\\": "%s/src/"', __DIR__.'../../../'),
175+
'replace' => sprintf('"App\\\Tests\\\": "tests/",'."\n".' "Symfony\\\Bundle\\\MakerBundle\\\": "%s/src/"', str_replace('\\', '\\\\', __DIR__.'../../..')),
172176
],
173177
];
174178
$this->processReplacements($replacements, self::$flexProjectPath);

tests/DependencyBuilderTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function testGetMissingPackagesMessage(array $missingPackages, array $mis
5555
$depBuilder->addClassDependency('Foo', $missingPackage, true, true);
5656
}
5757

58+
// normalize line breaks on Windows for comparison
59+
$expectedMessage = str_replace("\r\n", "\n", $expectedMessage);
5860
$this->assertSame($expectedMessage, $depBuilder->getMissingPackagesMessage('make:something'));
5961
}
6062

tests/FileManagerTest.php

+36
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public function getRelativizePathTests()
4545
'/home/project/foo/bar/../../src/Baz.php',
4646
'src/Baz.php',
4747
];
48+
49+
yield 'windows_path' => [
50+
'D:\path\to\project',
51+
'D:\path\to\project\vendor\composer/../../src/Controller/TestController.php',
52+
'src/Controller/TestController.php',
53+
];
4854
}
4955

5056
public function testGetPathForFutureClass()
@@ -96,4 +102,34 @@ public function getPathForFutureClassTests()
96102
'Psr0\Package\Admin\Bar' => 'lib/other/Psr0/Package/Admin/Bar.php'
97103
];
98104
}
105+
106+
/**
107+
* @dataProvider getAbsolutePathTests
108+
*/
109+
public function testAbsolutizePath(string $rootDir, string $path, string $expectedPath)
110+
{
111+
$fileManager = new FileManager(new Filesystem(), $rootDir);
112+
$this->assertSame($expectedPath, $fileManager->absolutizePath($path));
113+
}
114+
115+
public function getAbsolutePathTests()
116+
{
117+
yield 'normal_path_change' => [
118+
'/home/project/',
119+
'foo/bar',
120+
'/home/project/foo/bar',
121+
];
122+
123+
yield 'already_absolute_path' => [
124+
'/home/project/',
125+
'/foo/bar',
126+
'/foo/bar',
127+
];
128+
129+
yield 'windows_already_absolute_path' => [
130+
'D:\path\to\project',
131+
'D:\foo\bar',
132+
'D:\foo\bar',
133+
];
134+
}
99135
}

tests/Maker/FunctionalTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getCommandTests()
155155
'mysql://db_user:[email protected]:3306/db_name',
156156
'sqlite:///%kernel.project_dir%/var/app.db'
157157
)
158-
->addPostMakeCommand('./bin/console doctrine:schema:create --env=test')
158+
->addPostMakeCommand('php bin/console doctrine:schema:create --env=test')
159159
];
160160

161161
yield 'fixtures' => [MakerTestDetails::createTest(
@@ -306,7 +306,7 @@ public function getCommandTests()
306306
)
307307
->addExtraDependencies('doctrine/orm')
308308
// sync the database, so no changes are needed
309-
->addPreMakeCommand('./bin/console doctrine:schema:create --env=test')
309+
->addPreMakeCommand('php bin/console doctrine:schema:create --env=test')
310310
->assert(function(string $output, string $directory) {
311311
$this->assertNotContains('Success', $output);
312312

0 commit comments

Comments
 (0)