Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c81b923

Browse files
committed
fix fopen flags
1 parent c40cf26 commit c81b923

38 files changed

+54
-54
lines changed

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function paramProvider()
126126
array(true, array(), true, true),
127127
array(null, array(), null, true),
128128
array(new \DateTime('2011-09-11'), array('date'), '2011-09-11', true),
129-
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
129+
array(fopen(__FILE__, 'rb'), array(), 'Resource(stream)', false),
130130
array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', false),
131131
);
132132
}

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private function openOutputStream()
136136
{
137137
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
138138

139-
return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
139+
return @fopen($outputStream, 'wb') ?: fopen('php://output', 'wb');
140140
}
141141

142142
/**
@@ -146,6 +146,6 @@ private function openErrorStream()
146146
{
147147
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
148148

149-
return fopen($errorStream, 'w');
149+
return fopen($errorStream, 'wb');
150150
}
151151
}

src/Symfony/Component/Console/Tester/ApplicationTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function run(array $input, $options = array())
6060
$this->input->setInteractive($options['interactive']);
6161
}
6262

63-
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
63+
$this->output = new StreamOutput(fopen('php://memory', 'wb', false));
6464
if (isset($options['decorated'])) {
6565
$this->output->setDecorated($options['decorated']);
6666
}

src/Symfony/Component/Console/Tester/CommandTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function execute(array $input, array $options = array())
6464
$this->input->setInteractive($options['interactive']);
6565
}
6666

67-
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
67+
$this->output = new StreamOutput(fopen('php://memory', 'wb', false));
6868
$this->output->setDecorated(isset($options['decorated']) ? $options['decorated'] : false);
6969
if (isset($options['verbosity'])) {
7070
$this->output->setVerbosity($options['verbosity']);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ public function testVerboseValueNotBreakArguments()
742742
$application->setCatchExceptions(false);
743743
$application->add(new \FooCommand());
744744

745-
$output = new StreamOutput(fopen('php://memory', 'w', false));
745+
$output = new StreamOutput(fopen('php://memory', 'wb', false));
746746

747747
$input = new ArgvInput(array('cli.php', '-v', 'foo:bar'));
748748
$application->run($input, $output);

src/Symfony/Component/Console/Tests/Helper/LegacyDialogHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function testNoInteraction()
229229

230230
protected function getInputStream($input)
231231
{
232-
$stream = fopen('php://memory', 'r+', false);
232+
$stream = fopen('php://memory', 'r+b', false);
233233
fwrite($stream, $input);
234234
rewind($stream);
235235

@@ -238,7 +238,7 @@ protected function getInputStream($input)
238238

239239
protected function getOutputStream()
240240
{
241-
return new StreamOutput(fopen('php://memory', 'r+', false));
241+
return new StreamOutput(fopen('php://memory', 'r+b', false));
242242
}
243243

244244
protected function getConsoleOutput($stderr)

src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function testNonDecoratedOutput()
208208

209209
protected function getOutputStream($decorated = true)
210210
{
211-
return new StreamOutput(fopen('php://memory', 'r+', false), StreamOutput::VERBOSITY_NORMAL, $decorated);
211+
return new StreamOutput(fopen('php://memory', 'r+b', false), StreamOutput::VERBOSITY_NORMAL, $decorated);
212212
}
213213

214214
protected $lastMessagesLength;

src/Symfony/Component/Console/Tests/Helper/LegacyTableHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LegacyTableHelperTest extends TestCase
2424

2525
protected function setUp()
2626
{
27-
$this->stream = fopen('php://memory', 'r+');
27+
$this->stream = fopen('php://memory', 'r+b');
2828
}
2929

3030
protected function tearDown()

src/Symfony/Component/Console/Tests/Helper/ProcessHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function provideCommandsAndOutput()
107107

108108
private function getOutputStream($verbosity)
109109
{
110-
return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, false);
110+
return new StreamOutput(fopen('php://memory', 'r+b', false), $verbosity, false);
111111
}
112112

113113
private function getOutput(StreamOutput $output)

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ public function provideFormat()
656656

657657
protected function getOutputStream($decorated = true, $verbosity = StreamOutput::VERBOSITY_NORMAL)
658658
{
659-
return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, $decorated);
659+
return new StreamOutput(fopen('php://memory', 'r+b', false), $verbosity, $decorated);
660660
}
661661

662662
protected function generateOutput($expected)

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ public function testTraversableAutocomplete()
578578

579579
protected function getInputStream($input)
580580
{
581-
$stream = fopen('php://memory', 'r+', false);
581+
$stream = fopen('php://memory', 'r+b', false);
582582
fwrite($stream, $input);
583583
rewind($stream);
584584

@@ -587,7 +587,7 @@ protected function getInputStream($input)
587587

588588
protected function createOutputInterface()
589589
{
590-
return new StreamOutput(fopen('php://memory', 'r+', false));
590+
return new StreamOutput(fopen('php://memory', 'r+b', false));
591591
}
592592

593593
protected function createInputInterfaceMock($interactive = true)

src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testAskThrowsExceptionOnMissingInput()
125125

126126
protected function getInputStream($input)
127127
{
128-
$stream = fopen('php://memory', 'r+', false);
128+
$stream = fopen('php://memory', 'r+b', false);
129129
fwrite($stream, $input);
130130
rewind($stream);
131131

@@ -134,7 +134,7 @@ protected function getInputStream($input)
134134

135135
protected function createOutputInterface()
136136
{
137-
$output = new StreamOutput(fopen('php://memory', 'r+', false));
137+
$output = new StreamOutput(fopen('php://memory', 'r+b', false));
138138
$output->setDecorated(false);
139139

140140
return $output;

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TableTest extends TestCase
2424

2525
protected function setUp()
2626
{
27-
$this->stream = fopen('php://memory', 'r+');
27+
$this->stream = fopen('php://memory', 'r+b');
2828
}
2929

3030
protected function tearDown()

src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function testContextCanContainAnything()
140140
'float' => 0.5,
141141
'nested' => array('with object' => new DummyTest()),
142142
'object' => new \DateTime(),
143-
'resource' => fopen('php://memory', 'r'),
143+
'resource' => fopen('php://memory', 'rb'),
144144
);
145145

146146
$this->getLogger()->warning('Crazy context data', $context);

src/Symfony/Component/Console/Tests/Output/StreamOutputTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StreamOutputTest extends TestCase
2121

2222
protected function setUp()
2323
{
24-
$this->stream = fopen('php://memory', 'a', false);
24+
$this->stream = fopen('php://memory', 'ab', false);
2525
}
2626

2727
protected function tearDown()

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
5353

5454
if ($doCopy) {
5555
// https://bugs.php.net/bug.php?id=64634
56-
if (false === $source = @fopen($originFile, 'r')) {
56+
if (false === $source = @fopen($originFile, 'rb')) {
5757
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
5858
}
5959

6060
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
61-
if (false === $target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true))))) {
61+
if (false === $target = @fopen($targetFile, 'wb', null, stream_context_create(array('ftp' => array('overwrite' => true))))) {
6262
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
6363
}
6464

src/Symfony/Component/Filesystem/LockHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public function lock($blocking = false)
7575
$error = $msg;
7676
});
7777

78-
if (!$this->handle = fopen($this->file, 'r')) {
79-
if ($this->handle = fopen($this->file, 'x')) {
78+
if (!$this->handle = fopen($this->file, 'rb')) {
79+
if ($this->handle = fopen($this->file, 'xb')) {
8080
chmod($this->file, 0444);
81-
} elseif (!$this->handle = fopen($this->file, 'r')) {
81+
} elseif (!$this->handle = fopen($this->file, 'rb')) {
8282
usleep(100); // Give some time for chmod() to complete
83-
$this->handle = fopen($this->file, 'r');
83+
$this->handle = fopen($this->file, 'rb');
8484
}
8585
}
8686
restore_error_handler();

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ public function getContent($asResource = false)
15251525

15261526
// Content passed in parameter (test)
15271527
if (is_string($this->content)) {
1528-
$resource = fopen('php://temp', 'r+');
1528+
$resource = fopen('php://temp', 'r+b');
15291529
fwrite($resource, $this->content);
15301530
rewind($resource);
15311531

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ private function getInsertStatement($sessionId, $sessionData, $maxlifetime)
669669
{
670670
switch ($this->driver) {
671671
case 'oci':
672-
$data = fopen('php://memory', 'r+');
672+
$data = fopen('php://memory', 'r+b');
673673
fwrite($data, $sessionData);
674674
rewind($data);
675675
$sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, EMPTY_BLOB(), :lifetime, :time) RETURNING $this->dataCol into :data";
@@ -702,7 +702,7 @@ private function getUpdateStatement($sessionId, $sessionData, $maxlifetime)
702702
{
703703
switch ($this->driver) {
704704
case 'oci':
705-
$data = fopen('php://memory', 'r+');
705+
$data = fopen('php://memory', 'r+b');
706706
fwrite($data, $sessionData);
707707
rewind($data);
708708
$sql = "UPDATE $this->table SET $this->dataCol = EMPTY_BLOB(), $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id RETURNING $this->dataCol into :data";

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testRequests($requestRange, $offset, $length, $responseRange)
9696
$request->headers->set('If-Range', $etag);
9797
$request->headers->set('Range', $requestRange);
9898

99-
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
99+
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'rb');
100100
fseek($file, $offset);
101101
$data = fread($file, $length);
102102
fclose($file);
@@ -127,7 +127,7 @@ public function testRequestsWithoutEtag($requestRange, $offset, $length, $respon
127127
$request->headers->set('If-Range', $lastModified);
128128
$request->headers->set('Range', $requestRange);
129129

130-
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
130+
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'rb');
131131
fseek($file, $offset);
132132
$data = fread($file, $length);
133133
fclose($file);
@@ -182,7 +182,7 @@ public function testFullFileRequests($requestRange)
182182
$request = Request::create('/');
183183
$request->headers->set('Range', $requestRange);
184184

185-
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
185+
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'rb');
186186
$data = fread($file, 35);
187187
fclose($file);
188188

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ public function testGetContentReturnsResourceWhenContentSetInConstructor()
10201020

10211021
public function testContentAsResource()
10221022
{
1023-
$resource = fopen('php://memory', 'r+');
1023+
$resource = fopen('php://memory', 'r+b');
10241024
fwrite($resource, 'My other content');
10251025
rewind($resource);
10261026

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
5757
return array();
5858
}
5959

60-
$file = fopen($file, 'r');
60+
$file = fopen($file, 'rb');
6161
fseek($file, 0, SEEK_END);
6262

6363
$result = array();
@@ -170,7 +170,7 @@ public function write(Profile $profile)
170170

171171
if (!$profileIndexed) {
172172
// Add to index
173-
if (false === $file = fopen($this->getIndexFilename(), 'a')) {
173+
if (false === $file = fopen($this->getIndexFilename(), 'ab')) {
174174
return false;
175175
}
176176

src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getCollectTestData()
5151
),
5252
array(
5353
1,
54-
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')), 'priority' => 100, 'priorityName' => 'DEBUG')),
54+
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'rb')), 'priority' => 100, 'priorityName' => 'DEBUG')),
5555
array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
5656
0,
5757
0,

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected function createRequest()
163163
$request->attributes->set('foo', 'bar');
164164
$request->attributes->set('_route', 'foobar');
165165
$request->attributes->set('_route_params', array('name' => 'foo'));
166-
$request->attributes->set('resource', fopen(__FILE__, 'r'));
166+
$request->attributes->set('resource', fopen(__FILE__, 'rb'));
167167
$request->attributes->set('object', new \stdClass());
168168

169169
return $request;

src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testMultiRowIndexFile()
7373
$storage->write($profile);
7474
}
7575

76-
$handle = fopen(self::$tmpDir.'/index.csv', 'r');
76+
$handle = fopen(self::$tmpDir.'/index.csv', 'rb');
7777
for ($i = 0; $i < $iteration; ++$i) {
7878
$row = fgetcsv($handle);
7979
$this->assertEquals('token'.$i, $row[0]);

src/Symfony/Component/Intl/Data/Bundle/Writer/TextBundleWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TextBundleWriter implements BundleWriterInterface
3333
*/
3434
public function write($path, $locale, $data, $fallback = true)
3535
{
36-
$file = fopen($path.'/'.$locale.'.txt', 'w');
36+
$file = fopen($path.'/'.$locale.'.txt', 'wb');
3737

3838
$this->writeResourceBundle($file, $locale, $data, $fallback);
3939

src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public function provideInvalidTypes()
523523
return array(
524524
array(true, 'string', 'The option "option" with value true is expected to be of type "string", but is of type "boolean".'),
525525
array(false, 'string', 'The option "option" with value false is expected to be of type "string", but is of type "boolean".'),
526-
array(fopen(__FILE__, 'r'), 'string', 'The option "option" with value resource is expected to be of type "string", but is of type "resource".'),
526+
array(fopen(__FILE__, 'rb'), 'string', 'The option "option" with value resource is expected to be of type "string", but is of type "resource".'),
527527
array(array(), 'string', 'The option "option" with value array is expected to be of type "string", but is of type "array".'),
528528
array(new OptionsResolver(), 'string', 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".'),
529529
array(42, 'string', 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".'),

src/Symfony/Component/Process/Pipes/UnixPipes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __destruct()
4646
public function getDescriptors()
4747
{
4848
if ($this->disableOutput) {
49-
$nullstream = fopen('/dev/null', 'c');
49+
$nullstream = fopen('/dev/null', 'cb');
5050

5151
return array(
5252
array('pipe', 'r'),

src/Symfony/Component/Process/Pipes/WindowsPipes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function __destruct()
9494
public function getDescriptors()
9595
{
9696
if ($this->disableOutput) {
97-
$nullstream = fopen('NUL', 'c');
97+
$nullstream = fopen('NUL', 'cb');
9898

9999
return array(
100100
array('pipe', 'r'),

src/Symfony/Component/Process/Process.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function start($callback = null)
279279

280280
// Workaround for the bug, when PTS functionality is enabled.
281281
// @see : https://bugs.php.net/69442
282-
$ptsWorkaround = fopen(__FILE__, 'r');
282+
$ptsWorkaround = fopen(__FILE__, 'rb');
283283
}
284284

285285
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
@@ -1413,8 +1413,8 @@ private function resetProcessData()
14131413
$this->exitcode = null;
14141414
$this->fallbackStatus = array();
14151415
$this->processInformation = null;
1416-
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
1417-
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
1416+
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+b');
1417+
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+b');
14181418
$this->process = null;
14191419
$this->latestSignal = null;
14201420
$this->status = self::STATUS_READY;

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function testSetStreamAsInput($code, $size)
199199
$expected = str_repeat(str_repeat('*', 1024), $size).'!';
200200
$expectedLength = (1024 * $size) + 1;
201201

202-
$stream = fopen('php://temporary', 'w+');
202+
$stream = fopen('php://temporary', 'w+b');
203203
fwrite($stream, $expected);
204204
rewind($stream);
205205

@@ -215,7 +215,7 @@ public function testSetStreamAsInput($code, $size)
215215

216216
public function testLiveStreamAsInput()
217217
{
218-
$stream = fopen('php://memory', 'r+');
218+
$stream = fopen('php://memory', 'r+b');
219219
fwrite($stream, 'hello');
220220
rewind($stream);
221221

@@ -368,7 +368,7 @@ public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
368368

369369
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('file_put_contents($s = \''.$uri.'\', \'foo\'); flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');')));
370370

371-
$h = fopen($lock, 'w');
371+
$h = fopen($lock, 'wb');
372372
flock($h, LOCK_EX);
373373

374374
$p->start();

0 commit comments

Comments
 (0)