This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I am new to Unit testing and I am trying to create some tests for the functions within AppModel.php in CakePHP 2.0.
My AppModelTest.php looks like:
<?php
App::uses('AppModel', 'Model');
class AppModelTestCase extends CakeTestCase {
public $fixtures = array();
public function setUp() {
parent::setUp();
$this->AppModel = ClassRegistry::init('AppModel');
}
public function tearDown() {
unset($this->AppModel);
ClassRegistry::flush();
parent::tearDown();
}
public function testMultibyteSlug() {
$result = $this->AppModel->slug('abet!"£$%*$%^&yurgerfui94873');
$this->assertEqual($result, 'abet-yurgerfui94873');
.....
When I try to run the tests I get:
MissingTableException
Database table app_models for model AppModel was not found.
Test case: AppModelTestCase(testMultibyteSlug)
Stack trace:
C:\xampp\htdocs\wdmmg2\lib\Cake\Model\Model.php : 3258
C:\xampp\htdocs\wdmmg2\lib\Cake\Model\Model.php : 720
C:\xampp\htdocs\wdmmg2\app\Test\Case\Model\AppModelTest.php : 39
C:\xampp\htdocs\wdmmg2\app\Test\Case\Model\AppModelTest.php : 39
AppModelTestCase::testMultibyteSlug
Can anybody help me as I do not know where to start or what I am doing wrong. Thanks.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How do we implement schedulable state in corda? In my case i need to issue a monthly statement, so can schedulablestate be used for this?
There are a number of things you need to do.
Firstly, your state object needs to implement the SchedulableState interface. It adds an additional method:
interface SchedulableState : ContractState {
/**
* Indicate whether there is some activity to be performed at some future point in time with respect to this
* [ContractState], what that activity is and at what point in time it should be initiated.
* This can be used to implement deadlines for payment or processing of financial instruments according to a schedule.
*
* The state has no reference to it's own StateRef, so supply that for use as input to any FlowLogic constructed.
*
* #return null if there is no activity to schedule.
*/
fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity?
}
This interface requires a method named nextScheduledActivity to be implemented which returns an optional ScheduledActivity instance. ScheduledActivity captures what FlowLogic instance each node will run, to perform the activity, and when it will run is described by a java.time.Instant. Once your state implements this interface and is tracked by the vault, it can expect to be queried for the next activity when committed to the vault. Example:
class ExampleState(val initiator: Party,
val requestTime: Instant,
val delay: Long) : SchedulableState {
override val contract: Contract get() = DUMMY_PROGRAM_ID
override val participants: List<AbstractParty> get() = listOf(initiator)
override fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity? {
val responseTime = requestTime.plusSeconds(delay)
val flowRef = flowLogicRefFactory.create(FlowToStart::class.java)
return ScheduledActivity(flowRef, responseTime)
}
}
Secondly, the FlowLogic class which is schedulted to start (in this case FlowToStart) must be also annotated with #SchedulableFlow. E.g.
#InitiatingFlow
#SchedulableFlow
class FlowToStart : FlowLogic<Unit>() {
#Suspendable
override fun call() {
// Do stuff.
}
}
Now, when ExampleState is stored in the vault, the FlowToStart will be schedulted to start at the offset time specified in the ExampleState.
That's it!
This question already has answers here:
How do I call ::std::make_shared on a class with only protected or private constructors?
(19 answers)
Closed 7 years ago.
I am currently following the book **Effective Modern C++" and it says
Avoid creating std::shared_ptrs from variables of raw pointer type.
And I am convinced with the explanation so that I, too, agree on that we need to avoid. But there is an exception I encountered.
class Person
{
protected:
Person();
public:
static std::shared_ptr<Person> getShared()
{
return std::shared_ptr<Person>(new Person());
}
When we hide the default constructor std::make_shared cannot do its job. That's why I use a static method in the example above. My question is
Is this best I can do about the situation?
I still use raw pointer to create a shared_ptr, but in this case I can predict what may happen to this pointer. Does this practice still threaten my code?
Although this might not be the best way to do that, one way to do get your constructor protected to a certain degree but still make it callable by std::make_shared is the following:
class MyClass
{
protected:
struct ConstructorGuard {};
public:
MyClass(ConstructorGuard g) {}
static std::shared_ptr<MyClass> create()
{
return std::make_shared<MyClass>(ConstructorGuard());
}
};
The constructor itself is public, but it cannot be called from outside the class, because it requires an argument of type ConstructorGuard which is a protected nested class, such that only the class itself (and the derived classes) can construct such an object to pass it to the constructor.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What's the best way(s) to implement a "cancel" button feature (say for a dialog which uses some shared model & two way bindings)?
The obvious solution of copying every field in the object into a "revert" obj defeats the purpose (might as well just set each value manually upon a save). I've used ObjectUtil.copy/clone in the past, but I'm not aware of all the caveats with more complex data types which contain lists, etc. (Deep vs. Shallow copy)
Are there any better/other methods?
Please read AS3 - Clone an object
For complex Value Objects will be good using the ByteArray class for creation clone.
But make sure that you are using [RemoteClass] or registerClassAlias for all classes that you what to clone.
I've had issues with the builtin ObjectUtil.clone() and ObjectUtil.copy() methods. Thats why I created my own version that uses introspection instead using ByteArray.
One method copies all properties from one instance to another:
private static const rw:String = "readwrite";
public static function copyProperties(source:Object, target:Object):void {
if (!source || !target) return;
//copy properties declared in Class definition
var sourceInfo:XML = describeType(source);
var propertyLists:Array = [sourceInfo.variable, sourceInfo.accessor];
for each (var propertyList:XMLList in propertyLists) {
for each (var property:XML in propertyList) {
if (property.#access == undefined || property.#access == rw) {
var name:String = property.#name;
if (target.hasOwnProperty(name)) target[name] = source[name];
}
}
}
//copy dynamic properties
for (name in source)
if (target.hasOwnProperty(name))
target[name] = source[name];
}
The other creates a complete clone of an object by copying all its properties to a new instance:
public static function clone(source:Object):* {
var Clone:Class = getDefinitionByName(getQualifiedClassName(source)) as Class;
var clone:* = new Clone();
copyProperties(source, clone);
return clone;
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm attempting to add a mirgration before I run my project.
I get the following error when I attempt to add a mirgration
One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'MembershipUser' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'MembershipUsers' is based on type 'MembershipUser' that has no keys defined.
Here is the class:
<Table("aspnet_Membership")>
Public Class UserMembership
Inherits User
Public Property ApplicationId As Guid
Public Property Comment As String
End Class
Its parent:
<ReadOnlyAttribute(True), Table("aspnet_Users")>
Public Class User
<Key, DatabaseGenerated(DatabaseGeneratedOption.Identity), DisplayName("User Id")>
Public Property UserId As Guid
<Required, StringLength(256)>
Public Property UserName As String
<Required, StringLength(256)>
Public Property LoweredUserName As String
<StringLength(16)>
Public Property MobileAlias As String
<Required>
Public Property IsAnonymous As Boolean
<Required>
Public Property LastActivityDate As DateTime
End Class
Finally OnModelCreating:
modelBuilder.Entity(Of MembershipUser)().Map(Sub(m)
m.MapInheritedProperties()
m.ToTable("aspnet_Membership")
End Sub)
Anyone know what I'm doing wrong?
The exception talks about MembershipUser but your class has the name UserMembership. Is this a typo?
I am solidifying my understanding of the relationship between Liskov Substitutional Principal and Open Close Principal. If anybody could confirm my deductions and answer my questions below that would be great.
I have the following classes. As you can see, B is derived from A and it is overriding the DisplayMessage function in order to alter the behavior.
public class A
{
private readonly string _message;
public A(string message)
{
_message = message;
}
public virtual void DisplayMessage()
{
Console.WriteLine(_message);
}
}
public class B : A
{
public B(string message) : base(message){}
public override void DisplayMessage()
{
Console.WriteLine("I'm overwriting the expected behavior of A::DisplayMessage() and violating LSP >:-D");
}
}
Now in my bootstrap program, ShowClassTypeis expecting an object of Type A which should helpfully write out what class Type it is. However B is violating LSP so when it's DisplayMessage function is called it prints a completely unexpected message and essentially interferes with the intended purpose of ShowClassType.
class Program
{
static void Main(string[] args)
{
A a = new A("I am A");
B b = new B("I am B");
DoStuff(b);
Console.ReadLine();
}
private static void ShowClassType(A model)
{
Console.WriteLine("What Class are you??");
model.DisplayMessage();
}
}
So my question is, am I right to conclude that ShowClassType is now violating the Open Close Principal because now that Type B can come in and change the expected function of that method, it is no longer closed for modification (ie. to ensure it maintains it's expected behaviour you would have to alter it so that it first checks to make sure we are only working with an original A object)?
Or, inversely is this just a good example to show that ShowClassType is closed for modification and that by passing in a derived type (albeit a LSP violating one) we have extended what it is meant to do?
Lastly, is it bad practice to create virtual functions on Base classes if the base class is not abstract? By doing so, are we not just inviting derived classes to violate the Liskov Substitution principal?
Cheers
I'd say it's not ShowClassType that is violating the Open/Closed Principle.
It's only class B that is violating the Liskov Substitution Principle. A is Open for extension, but closed for modification.
From Wikipedia,
an entity can allow its behaviour to be modified without altering its source code.
It's obvious that the source code of A is not modified. Nor are private members of A being used (which would also be a violation of the Open/Closed principle in my book). B strictly uses the public interface of A, so although the Open/Closed principle is obeyed the Liskov Substitution Principle is violated.
The last question is worth a discussion in and of itself. A related question on SO is here.
I think it is not violate not LSP and not OCP in THIS context of using.
For my opinion, ShowClassType not violation OCP:
1. Function can not break OCP, only class architecture can do this.
2. You can add new behaviours to derived classes from A - so it do not break OCP
What about LSP? Your reason - user not expected get this message? But he got some message! If function overriding returns some message i think is ok in THIS context of your code.
If function, that add two numbers is overrides, and 1+1 returns 678 it not expectable for me and is bad. BUT, if for scientist of Physics from Mars planet it can be good answer.
DO NOT ANALYSE PROBLEM WITHOUT ALL CONTEXT!!! You must get whole picture of problem. And, of course