Skip to main content
Made answer more direct
Source Link
Josh K
  • 23k
  • 10
  • 68
  • 100

The short answer is no.

You cannot effectively test JavaScript with PHP. To do it effectively, you need to use JavaScript.

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).

Edit

Unit testing frameworks are most efficient and useful when you are using the same language to test as you are to write the code in. For that reason we have PHP unit testing frameworks, Java unit testing frameworks, C#/.Net unit testing frameworks, and yes, JavaScript unit testing frameworks. A big part of the reason for this is that your unit tests need to examine the results of what your code is doing in the environment where it runs. SimpleTest runs in the PHP environment, and examines to assert that your PHP functions are doing what you expect. It doesn't run directly in the client browser, but as all PHP code it runs on the server and generates HTML output.

In order to run and test JavaScript functionality--particularly when the problem might be how a one browser implements it--you need to execute and assert functionality in JavaScript. Now, you can roll your own JavaScript unit testing framework for your environment, or you can use one that already exists.

The JavaScript lives 100% on the client side. That's why you didn't see anything about running JavaScript and PHP together--just as you won't find information on Java and JavaScript together (in the same context we are talking here).

The short answer is no. You cannot effectively test JavaScript with PHP. To do it effectively, you need to use JavaScript.

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).

Edit

Unit testing frameworks are most efficient and useful when you are using the same language to test as you are to write the code in. For that reason we have PHP unit testing frameworks, Java unit testing frameworks, C#/.Net unit testing frameworks, and yes, JavaScript unit testing frameworks. A big part of the reason for this is that your unit tests need to examine the results of what your code is doing in the environment where it runs. SimpleTest runs in the PHP environment, and examines to assert that your PHP functions are doing what you expect. It doesn't run directly in the client browser, but as all PHP code it runs on the server and generates HTML output.

In order to run and test JavaScript functionality--particularly when the problem might be how a one browser implements it--you need to execute and assert functionality in JavaScript. Now, you can roll your own JavaScript unit testing framework for your environment, or you can use one that already exists.

The JavaScript lives 100% on the client side. That's why you didn't see anything about running JavaScript and PHP together--just as you won't find information on Java and JavaScript together (in the same context we are talking here).

The short answer is no. You cannot effectively test JavaScript with PHP. To do it effectively, you need to use JavaScript.

The short answer is no.

You cannot effectively test JavaScript with PHP. To do it effectively, you need to use JavaScript.

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).

Unit testing frameworks are most efficient and useful when you are using the same language to test as you are to write the code in. For that reason we have PHP unit testing frameworks, Java unit testing frameworks, C#/.Net unit testing frameworks, and yes, JavaScript unit testing frameworks. A big part of the reason for this is that your unit tests need to examine the results of what your code is doing in the environment where it runs. SimpleTest runs in the PHP environment, and examines to assert that your PHP functions are doing what you expect. It doesn't run directly in the client browser, but as all PHP code it runs on the server and generates HTML output.

In order to run and test JavaScript functionality--particularly when the problem might be how a one browser implements it--you need to execute and assert functionality in JavaScript. Now, you can roll your own JavaScript unit testing framework for your environment, or you can use one that already exists.

The JavaScript lives 100% on the client side. That's why you didn't see anything about running JavaScript and PHP together--just as you won't find information on Java and JavaScript together (in the same context we are talking here).

clarification on why my answer doesn't change.
Source Link
Berin Loritsch
  • 46.5k
  • 7
  • 93
  • 164

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).

Edit

Unit testing frameworks are most efficient and useful when you are using the same language to test as you are to write the code in. For that reason we have PHP unit testing frameworks, Java unit testing frameworks, C#/.Net unit testing frameworks, and yes, JavaScript unit testing frameworks. A big part of the reason for this is that your unit tests need to examine the results of what your code is doing in the environment where it runs. SimpleTest runs in the PHP environment, and examines to assert that your PHP functions are doing what you expect. It doesn't run directly in the client browser, but as all PHP code it runs on the server and generates HTML output.

In order to run and test JavaScript functionality--particularly when the problem might be how a one browser implements it--you need to execute and assert functionality in JavaScript. Now, you can roll your own JavaScript unit testing framework for your environment, or you can use one that already exists.

The JavaScript lives 100% on the client side. That's why you didn't see anything about running JavaScript and PHP together--just as you won't find information on Java and JavaScript together (in the same context we are talking here).

The short answer is no. You cannot effectively test JavaScript with PHP. To do it effectively, you need to use JavaScript.

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).

Edit

Unit testing frameworks are most efficient and useful when you are using the same language to test as you are to write the code in. For that reason we have PHP unit testing frameworks, Java unit testing frameworks, C#/.Net unit testing frameworks, and yes, JavaScript unit testing frameworks. A big part of the reason for this is that your unit tests need to examine the results of what your code is doing in the environment where it runs. SimpleTest runs in the PHP environment, and examines to assert that your PHP functions are doing what you expect. It doesn't run directly in the client browser, but as all PHP code it runs on the server and generates HTML output.

In order to run and test JavaScript functionality--particularly when the problem might be how a one browser implements it--you need to execute and assert functionality in JavaScript. Now, you can roll your own JavaScript unit testing framework for your environment, or you can use one that already exists.

The JavaScript lives 100% on the client side. That's why you didn't see anything about running JavaScript and PHP together--just as you won't find information on Java and JavaScript together (in the same context we are talking here).

The short answer is no. You cannot effectively test JavaScript with PHP. To do it effectively, you need to use JavaScript.

Source Link
Berin Loritsch
  • 46.5k
  • 7
  • 93
  • 164

More than likely you will have to use a JavaScript unit testing library such as the one used for Prototype.js. Essentially, you need to be able to execute the JavaScript in browser, and get the results of the JavaScript run. You won't be able to do that from the server side (PHP).