From: Jeremy Mikola Date: Mon, 2 Mar 2015 19:41:48 +0000 (-0500) Subject: Regression tests for SplFileInfo class setters X-Git-Tag: php-5.5.24RC1~71^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dea7bc87860d409250e760d9be8b55f043a86f2b;p=php Regression tests for SplFileInfo class setters Adds tests for SplFileInfo class setters accepting either the base and child classes, and throwing an exception for unexpected classes. Related: http://svn.php.net/viewvc?view=revision&revision=336017 and https://github.com/facebook/hhvm/pull/4917 --- diff --git a/ext/spl/tests/SplFileInfo_setFileClass_basic.phpt b/ext/spl/tests/SplFileInfo_setFileClass_basic.phpt new file mode 100644 index 0000000000..00d9541b91 --- /dev/null +++ b/ext/spl/tests/SplFileInfo_setFileClass_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +SplFileInfo::setFileClass() expects SplFileObject or child class +--FILE-- +setFileClass('MyFileObject'); +echo get_class($info->openFile()), "\n"; + +$info->setFileClass('SplFileObject'); +echo get_class($info->openFile()), "\n"; + +?> +--EXPECT-- +MyFileObject +SplFileObject diff --git a/ext/spl/tests/SplFileInfo_setFileClass_error.phpt b/ext/spl/tests/SplFileInfo_setFileClass_error.phpt new file mode 100644 index 0000000000..7443998013 --- /dev/null +++ b/ext/spl/tests/SplFileInfo_setFileClass_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +SplFileInfo::setFileClass() throws exception for invalid class +--FILE-- +setFileClass('stdClass'); +} catch (UnexpectedValueException $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +SplFileInfo::setFileClass() expects parameter 1 to be a class name derived from SplFileObject, 'stdClass' given diff --git a/ext/spl/tests/SplFileInfo_setInfoClass_basic.phpt b/ext/spl/tests/SplFileInfo_setInfoClass_basic.phpt new file mode 100644 index 0000000000..fe19aca2ab --- /dev/null +++ b/ext/spl/tests/SplFileInfo_setInfoClass_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +SplFileInfo::setInfoClass() expects SplFileInfo or child class +--FILE-- +setInfoClass('MyInfoObject'); +echo get_class($info->getFileInfo()), "\n"; +echo get_class($info->getPathInfo()), "\n"; + +$info->setInfoClass('SplFileInfo'); +echo get_class($info->getFileInfo()), "\n"; +echo get_class($info->getPathInfo()), "\n"; + +?> +--EXPECT-- +MyInfoObject +MyInfoObject +SplFileInfo +SplFileInfo diff --git a/ext/spl/tests/SplFileInfo_setInfoClass_error.phpt b/ext/spl/tests/SplFileInfo_setInfoClass_error.phpt new file mode 100644 index 0000000000..aa884b30a0 --- /dev/null +++ b/ext/spl/tests/SplFileInfo_setInfoClass_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +SplFileInfo::setInfoClass() throws exception for invalid class +--FILE-- +setInfoClass('stdClass'); +} catch (UnexpectedValueException $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECTF-- +SplFileInfo::setInfoClass() expects parameter 1 to be a class name derived from SplFileInfo, 'stdClass' given