Jump to content

ProcessNetteTester and WireHttp


Guy Verville
 Share

Recommended Posts

Hi,

I have some problem configuring a test with wireHttp involved.

This code works ok on a real template (called testPageController.php). I have two local sites to make the test.

	public function getOtherSiteConnectionTest() {
		$config = wire("config");
		$http = new WireHttp();
		$chemin = "http://" . $config->afmqOtherSite . "   /en/afmq-services/hello/";
		$response = $http->get($chemin);
		$expected = "hello";
		$actual = $response;
		Assert::equal($expected, $actual);
	}

Nette Tester tells me it has forgotten to make the test which means a misconfiguration of a sort. What I did wrong?

 

 

NetteTester.png

Link to comment
Share on other sites

Sure! Of course, $path should be a valid path in your website.

<?php namespace ProcessWire;

use \Tester\Assert;
use \Tester\TestCase;

/**
 * @testCase
 */
class GetOtherSiteResponseTest extends TestCase {

	public function getOtherSiteConnectionTest() {
		$config = wire("config");
		$http = new WireHttp();
		$path = "http://" . $config->afmqOtherSite . "   /en/afmq-services/hello/";
		$response = $http->get($path);
		$expected = "Succès!";
		$actual = $response;
		Assert::equal($expected, $actual);
	}
}

(new GetOtherSiteResponseTest())->run();

The code of the template that responds is simple (this is crude test. I am using Twig templating).

<?php namespace ProcessWire;

require_once "MainController.php";

/**
 * Class AfmqServicesController
 * @package ProcessWire
 */
Class AfmqServicesController extends MainController {

	/**
	 * Simple test
     *
	 * @return void
	 */
	public function render(): void {
		$view = wire("view");
		$input = wire('input');
		$urlSegment = $input->urlSegment1;
		switch($urlSegment){
			case "hello":
				echo "OK";
				exit();
				break;
			default:
				exit();
				break;
		}
	}

}

(new AfmqServicesController())->render();

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...