Skip to content

Commit

Permalink
Fix Class "com.example.App+xp.web.dev.Console" could not be found
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 16, 2018
1 parent 9887e25 commit 6f8b42e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Web change log

## ?.?.? / ????-??-??

## 1.4.2 / 2018-08-16

* Fixed `Class "com.example.App+xp.web.dev.Console" could not be found`
errors when using development webserver.
(@thekid)

## 1.4.1 / 2018-08-14

* Changed `xp web` commandline to allow using filenames as application
Expand Down
11 changes: 8 additions & 3 deletions src/main/php/xp/web/Source.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
use lang\ClassLoader;
use lang\XPClass;

/**
* An application source
*
* @test xp://web.unittest.SourceTest
*/
class Source {
private $application;

Expand All @@ -17,10 +22,10 @@ public function __construct($name, $environment) {

if ('-' === $application) {
$this->application= new ServeDocumentRootStatically($environment);
} else if (is_file($name)) {
$this->application= ClassLoader::getDefault()->loadUri($name)->newInstance($environment);
} else if (is_file($application)) {
$this->application= ClassLoader::getDefault()->loadUri($application)->newInstance($environment);
} else {
$this->application= ClassLoader::getDefault()->loadClass($name)->newInstance($environment);
$this->application= ClassLoader::getDefault()->loadClass($application)->newInstance($environment);
}

if ($filters) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/php/web/unittest/HelloWorld.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace web\unittest;

use web\Application;

class HelloWorld extends Application {

/** @return var */
public function routes() {
return ['/' => function($req, $res) {
$res->answer(200);
$res->send('Hello World', 'text/plain');
}];
}
}
42 changes: 42 additions & 0 deletions src/test/php/web/unittest/SourceTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php namespace web\unittest;

use io\Path;
use lang\XPClass;
use unittest\TestCase;
use web\Environment;
use xp\web\ServeDocumentRootStatically;
use xp\web\Source;

class SourceTest extends TestCase {
private $environment;

/** @return void */
public function setUp() {
$this->environment= new Environment('dev', '.', 'static', []);
}

#[@test]
public function serve_document_root() {
$src= new Source('-', $this->environment);
$this->assertInstanceOf(ServeDocumentRootStatically::class, $src->application());
}

#[@test]
public function application_class() {
$src= new Source('web.unittest.HelloWorld', $this->environment);
$this->assertInstanceOf(HelloWorld::class, $src->application());
}

#[@test]
public function application_file() {
$base= XPClass::forName('web.unittest.HelloWorld')->getClassLoader()->path;
$src= new Source(new Path($base, 'web/unittest/HelloWorld.class.php'), $this->environment);
$this->assertInstanceOf(HelloWorld::class, $src->application());
}

#[@test]
public function application_class_and_filter() {
$src= new Source('web.unittest.HelloWorld+xp.web.dev.Console', $this->environment);
$this->assertInstanceOf(HelloWorld::class, $src->application());
}
}

0 comments on commit 6f8b42e

Please sign in to comment.