Skip to content

Additional tests for SplFileObject #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ext/pdo/tests/PDO_getAvailableDrivers_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
PDO::getAvailableDrivers basic
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
?>
--FILE--
<?php
print_r(PDO::getAvailableDrivers());
?>
--EXPECT--
Array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this test assumes only sqlite driver is available?

(
[0] => sqlite
)
12 changes: 12 additions & 0 deletions ext/pdo/tests/PDO_getAvailableDrivers_error001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
PDO::getAvailableDrivers error when argument supplied
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
?>
--FILE--
<?php
PDO::getAvailableDrivers('fakeArgument');
?>
--EXPECTF--
Warning: PDO::getAvailableDrivers() expects exactly 0 parameters, 1 given in %s on line %d
18 changes: 18 additions & 0 deletions ext/spl/tests/SplFileObject_current_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
SPL: SplFileObject::current basic
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
echo $s->current();

?>
--EXPECT--
<?php
19 changes: 19 additions & 0 deletions ext/spl/tests/SplFileObject_current_error001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
SPL: SplFileObject::current variation error
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
$s->seek(2);

echo $s->current('foo');
?>
--EXPECTF--
Warning: SplFileObject::current() expects exactly 0 parameters, 1 given in %s on line %d
21 changes: 21 additions & 0 deletions ext/spl/tests/SplFileObject_current_variation001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
SPL: SplFileObject::current variation
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
$s->seek(2);

echo $s->current();
echo $s->current();
?>
--EXPECT--
//line 3
//line 3
12 changes: 12 additions & 0 deletions ext/spl/tests/SplFileObject_getchildren_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
SPL: SplFileObject::getchildren basic
--CREDITS--
Erwin Poeze <erwin.poeze at gmail.com>
--FILE--
<?php
$s = new SplFileObject( __FILE__ );
var_dump($s->getChildren());

?>
--EXPECT--
NULL
12 changes: 12 additions & 0 deletions ext/spl/tests/SplFileObject_getchildren_error001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
SPL: SplFileObject::getchildren error 001
--CREDITS--
Erwin Poeze <erwin.poeze at gmail.com>
--FILE--
<?php
$s = new SplFileObject( __FILE__ );
$s->getChildren('string');

?>
--EXPECTF--
Warning: SplFileObject::getChildren() expects exactly 0 parameters, 1 given in %s on line %d
22 changes: 22 additions & 0 deletions ext/spl/tests/SplFileObject_getflags_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
SPL: SplFileObject::getFlags basic
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php

file_put_contents('testdata.csv', 'eerste;tweede;derde');

$fo = new SplFileObject('testdata.csv');

$fo->setFlags(SplFileObject::DROP_NEW_LINE);
var_dump($fo->getFlags());
?>
--CLEAN--
<?php
unlink('testdata.csv');
?>
--EXPECT--
int(1)
26 changes: 26 additions & 0 deletions ext/spl/tests/SplFileObject_getflags_error001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
SPL: SplFileObject::getFlags error 001
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php

file_put_contents('testdata.csv', 'eerste;tweede;derde');


$fo = new SplFileObject('testdata.csv');
$fo->setFlags(SplFileObject::READ_CSV);

$fo->setFlags(SplFileObject::DROP_NEW_LINE);

var_dump($fo->getFlags());

?>
--CLEAN--
<?php
unlink('testdata.csv');
?>
--EXPECT--
int(1)
21 changes: 21 additions & 0 deletions ext/spl/tests/SplFileObject_getflags_error002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
SPL: SplFileObject::getFlags error 001
--CREDITS--
Erwin Poeze <[email protected]>
--FILE--
<?php

file_put_contents('testdata.csv', 'eerste;tweede;derde');

$fo = new SplFileObject('testdata.csv');
$fo->setFlags(SplFileObject::READ_CSV);

$fo->getFlags('fake');

?>
--CLEAN--
<?php
unlink('testdata.csv');
?>
--EXPECTF--
Warning: SplFileObject::getFlags() expects exactly 0 parameters, 1 given in %s on line %d
29 changes: 29 additions & 0 deletions ext/spl/tests/SplFileObject_getflags_variation001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
SPL: SplFileObject::getFlags
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php

$fo = new SplFileObject(__FILE__);

$fo->setFlags(SplFileObject::DROP_NEW_LINE);
var_dump($fo->getFlags());

$fo->setFlags(SplFileObject::READ_AHEAD);
var_dump($fo->getFlags());

$fo->setFlags(SplFileObject::SKIP_EMPTY);
var_dump($fo->getFlags());

$fo->setFlags(SplFileObject::READ_CSV);
var_dump($fo->getFlags());

?>
--EXPECT--
int(1)
int(2)
int(4)
int(8)
12 changes: 12 additions & 0 deletions ext/spl/tests/SplFileObject_haschildren_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
SPL: SplFileObject::haschildren basic
--CREDITS--
Erwin Poeze <erwin.poeze at gmail.com>
--FILE--
<?php
$s = new SplFileObject( __FILE__ );
var_dump($s->hasChildren());

?>
--EXPECT--
bool(false)
12 changes: 12 additions & 0 deletions ext/spl/tests/SplFileObject_haschildren_error001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
SPL: SplFileObject::haschildren error 001
--CREDITS--
Erwin Poeze <erwin.poeze at gmail.com>
--FILE--
<?php
$s = new SplFileObject( __FILE__ );
$s->hasChildren('string');

?>
--EXPECTF--
Warning: SplFileObject::hasChildren() expects exactly 0 parameters, 1 given in %s on line %d
19 changes: 19 additions & 0 deletions ext/spl/tests/SplFileObject_key_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
SPL: SplFileObject::key basic
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);

$s->seek(3);
echo $s->key();
?>
--EXPECT--
3
22 changes: 22 additions & 0 deletions ext/spl/tests/SplFileObject_key_error001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
SPL: SplFileObject::key error
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);

$s->seek(12);
$s->next();
var_dump($s->key());
var_dump($s->valid());
?>
--EXPECT--
int(13)
bool(false)
22 changes: 22 additions & 0 deletions ext/spl/tests/SplFileObject_key_error002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
SPL: SplFileObject::key error
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);

$s->seek(120);
$s->next();
var_dump($s->key());
var_dump($s->valid());
?>
--EXPECT--
int(13)
bool(false)
15 changes: 15 additions & 0 deletions ext/spl/tests/SplFileObject_key_error003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
SPL: SplFileObject::key error
--CREDITS--
Erwin Poeze <erwin.poeze AT gmail.com>
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
$s->key(3);
?>
--EXPECTF--
Warning: SplFileObject::key() expects exactly 0 parameters, 1 given in %s on line %d
22 changes: 22 additions & 0 deletions ext/spl/tests/SplFileObject_next_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
SPL: SplFileObject::next basic
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
echo $s->current();
$s->next();

echo $s->current();

?>
--EXPECT--
<?php
//line 2
24 changes: 24 additions & 0 deletions ext/spl/tests/SplFileObject_next_variation001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
SPL: SplFileObject::next variation 001
--CREDITS--
Ricardo Oedietram <[email protected]>
Erwin Poeze <[email protected]>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);

$s->seek(13);
echo $s->current();

$s->next();
echo $s->current();
var_dump($s->valid());
?>
--EXPECT--
?>
bool(false)
Loading