You would have to mock the class, and not execute the constructor, but rather, build in the values you need and then use the mock in your tests.
Do you have a sample of what you have tried? You likely need to modify the Core() class to support dependency injection (the Config object and the Session object).
$stub = $this->getMock('Core');
// Configure the stub.
$stub->expects($this->any())
->method('CreateSession')
->will($this->returnValue('foo'));
$this->assertEquals('foo', $stub->CreateSession());
In your example code though, you will likely need to modify the Core() class to accept the Session and Config objects to be passed (either via the constructor, or via a Set dependency) and some modifications to the Session class as well.
class Core
{
private $SessionObject;
private $ConfigObject;
public function __construct(Config $Config, Session $Session) // Constructor Dependency
{
$this->ConfigObject = $Config;
$this->absUrl = $this->ConfigObject::get(Config::ABS_URL);
$this->baseDir = $this->ConfigObject::get(Config::BASE_DIR);
$this->session = $Session;
$this->session->SetSessionType('core');
return $this;
}
}
or
class Core
{
private $SessionObject;
private $ConfigObject;
public function __construct()
{
}
// Set Dependencies
public function SetConfigObject(Config $Config)
{
$this->ConfigObject = $Config;
}
public function SetSessionObject(Session $Session)
{
$this->SessionObject = $Session;
}
public function BuildObject($SessionType)
{
$this->absUrl = $this->ConfigObject::get(Config::ABS_URL);
$this->baseDir = $this->ConfigObject::get(Config::BASE_DIR);
$this->session->SetSessionType($SessionType);
}
}
Now your production code will pass the Config and Session objects properly, and you then use Mock objects in your tests to pass objects with the states that you need, to return hard set values when calling the get method on the object.