1
+ /**
2
+ * Copyright 2010-2012 by PHP-maven.org
3
+ *
4
+ * This file is part of phpexec-java.
5
+ *
6
+ * phpexec-java is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * phpexec-java is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with phpexec-java. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ package org .phpmaven .phpexec .library .test ;
21
+
22
+ import java .io .File ;
23
+
24
+ import junit .framework .Assert ;
25
+
26
+ import org .junit .Test ;
27
+ import org .phpmaven .phpexec .library .PhpCoreException ;
28
+ import org .phpmaven .phpexec .library .PhpExecutionException ;
29
+
30
+ /**
31
+ * test cases for PHP support.
32
+ *
33
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
34
+ * @since 0.1.8
35
+ */
36
+ public class Exception2Test {
37
+
38
+ /**
39
+ * Tests some things on php execution exception.
40
+ *
41
+ * @throws Exception thrown on errors
42
+ */
43
+ @ Test
44
+ public void testExecException () throws Exception {
45
+ PhpExecutionException ex = new PhpExecutionException (null , "FOO" );
46
+ Assert .assertEquals ("\n FOO" , ex .getMessage ());
47
+ final File fooFile = new File ("foo.php" );
48
+ ex = new PhpExecutionException (fooFile , "FOO" );
49
+ Assert .assertTrue (ex .getMessage ().contains ("FOO" ));
50
+ Assert .assertTrue (ex .getMessage ().contains (fooFile .getAbsolutePath ()));
51
+ }
52
+
53
+ /**
54
+ * Tests some things on php core exception.
55
+ *
56
+ * @throws Exception thrown on errors
57
+ */
58
+ @ Test
59
+ public void testCoreException () throws Exception {
60
+ // constructors for code coverage
61
+ PhpCoreException ex = new PhpCoreException ();
62
+ ex = new PhpCoreException ("FOO" , new Exception ());
63
+ ex = new PhpCoreException (new Exception ());
64
+
65
+ ex = new PhpCoreException ("some meaningful error" );
66
+ Assert .assertNull (ex .getAppendedOutput ());
67
+ Assert .assertEquals ("some meaningful error" , ex .getMessage ());
68
+ ex .appendOutput ("FOOBAR" );
69
+ Assert .assertEquals ("FOOBAR" , ex .getAppendedOutput ());
70
+ Assert .assertTrue (ex .getMessage ().contains ("FOOBAR" ));
71
+ Assert .assertTrue (ex .getMessage ().contains ("some meaningful error" ));
72
+ ex .appendOutput ("BAZ" );
73
+ Assert .assertEquals ("BAZ" , ex .getAppendedOutput ());
74
+ Assert .assertFalse (ex .getMessage ().contains ("FOOBAR" ));
75
+ Assert .assertTrue (ex .getMessage ().contains ("BAZ" ));
76
+ Assert .assertTrue (ex .getMessage ().contains ("some meaningful error" ));
77
+ }
78
+
79
+ }
0 commit comments